~wintershadows/dotfiles

ref: 8d34f2571e0dfbc995e1d5c9cb04f9acf02df4c5 dotfiles/.config/nvim/autoload/local/gui.vim -rw-r--r-- 2.8 KiB
8d34f257 — Mysterious Grass Add rust, adjust gitignores 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"" Shims for the Neovim-QT nvim_gui_shim.vim interface {{{
" Lifted from the original source:
" https://github.com/equalsraf/neovim-qt/blob/v0.2.16.1/src/gui/runtime/plugin/nvim_gui_shim.vim
function! local#gui#nvim_last_chan() abort
  return nvim_list_uis()[-1].chan
endfunction

function! local#gui#nvim_last_client_info() abort
  return nvim_get_chan_info(local#gui#nvim_last_chan()).client
endfunction

function! local#gui#nvim_gui_name() abort
  return 
    \ exists('GuiName()') 
      \ ? GuiName()
      \ : get(local#gui#nvim_last_client_info(), 'name', '')
endfunction

function! local#gui#loaded() abort
  return local#gui#nvim_gui_name() != ''
endfunction

function! local#gui#nvim_client_version() abort
  return get(local#gui#nvim_last_client_info(), 'version', {})
endfunction

function! local#gui#nvim_client_version_string() abort
  let l:version = local#gui#nvim_client_version()
  let l:version_parts = []

  if get(l:version, 'major', '') != ''
    let l:version_parts = add(l:version_parts, l:version.major)
  endif

  if get(l:version, 'minor', '') != ''
    let l:version_parts = add(l:version_parts, l:version.minor)
  endif

  if get(l:version, 'patch', '') != ''
    let l:version_parts = add(l:version_parts, l:version.patch)
  endif

  return join(l:version_parts, '.')
endfunction
" }}}

"" Font size adjustment {{{
" TODO: Instead of regex, ask equalsraf how to get current font size in
"       Neovim-Qt, if at all possible?
let s:fontsize_pattern = '\v:h\zs\d+%(\.\d+)?'

function! local#gui#fontsize_set(n)
  let &guifont = substitute(&guifont, s:fontsize_pattern, string(a:n), '')
endfunction

function! local#gui#fontsize_inc()
  let &guifont = substitute(&guifont, s:fontsize_pattern, '\=submatch(0)+1', '')
endfunction

function! local#gui#fontsize_dec()
  let &guifont = substitute(&guifont, s:fontsize_pattern, '\=submatch(0)-1', '')
endfunction

function! local#gui#fontsize_reset()
  let &guifont = substitute(&guifont, s:fontsize_pattern, g:gui_default_font_size, '')
endfunction

function! local#gui#set_font(name, options)
  if has('gui_vimr')
    " VimR doesn't support 'guifont'
    return
  endif

  let l:name = escape(a:name, ',')
  let l:val_parts = [l:name]

  let l:h = get(a:options, 'size', 0)
  if l:h
    let l:val_parts += ['h'.l:h]
  endif

  let l:w = get(a:options, 'weight', 0)
  if l:w
    let l:val_parts += ['w'.l:h]
  endif

  let l:i = get(a:options, 'italic', 0)
  if l:i
    let l:val_parts += ['i'.l:h]
  endif

  let l:b = get(a:options, 'bold', 0)
  if l:b
    let l:val_parts += ['b'.l:h]
  endif

  let l:sb = get(a:options, 'semibold', 0)
  if l:sb
    let l:val_parts += ['sb'.l:h]
  endif

  let l:l = get(a:options, 'light', 0)
  if l:l
    let l:val_parts += ['l'.l:h]
  endif

  let l:val = join(l:val_parts, ':')

  let &guifont = l:val
endfunction
" }}}