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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
-- ┏┓╻┏━╸┏━┓┏━┓╻ ╻┏━╸┏━╸╺┳╸ ┏━╸┏━┓┏┓╻┏━╸╻┏━╸
-- ┃┗┫┣╸ ┃ ┃┗━┓┣━┫┣╸ ┣╸ ┃ ┃ ┃ ┃┃┗┫┣╸ ┃┃╺┓
-- ╹ ╹┗━╸┗━┛┗━┛╹ ╹┗━╸┗━╸ ╹ ┗━╸┗━┛╹ ╹╹ ╹┗━┛
--
-- This is the default neosheet config. Without any config
-- neosheet is *not* capable of anything, since its basically just
-- a display for sheets.
--
-- All kinds of shortcuts and key presses and color schemes need
-- to be defined in this lua config file.
--
-- Let's bind the neosheet environment to a local variable so
-- it's easier to read and use.
--
local neosheet = require('neosheet')
-- ╺┳╸╻ ╻┏━╸┏┳┓┏━╸
-- ┃ ┣━┫┣╸ ┃┃┃┣╸
-- ╹ ╹ ╹┗━╸╹ ╹┗━╸
--
-- The following section defines the default theme of neosheet.
-- Every color value needs to have at least the following structure:
--
-- ```
-- {
-- fg = "#ffffff" -- or some other rgb color
-- bg = "#000000" -- same here.
-- }
-- ```
--
-- There are also some optional boolean values which ore by false by default:
--
-- * bold
-- * italic
-- * underlined
-- The following two function are just helper functions
-- to make our life easier.
--
-- The first function (`highlight_type`)
-- Takes a type-string, a switch-table and a fallback as arguments.
-- The switch-table shall contain all possible type-strings you might expect
-- for the variable given. The fallback is used if the type is not in the table.
--
-- The second function (`cell_fg`) is used to color the cells in the sheetview.
-- it only takes a type-string as argument and will return a color-string according
-- to the type given.
--
local function highlight_type(t, tbl, fallback)
local value = tbl[t]
if value == nil then
return fallback
end
return value
end
local function cell_fg(t)
return highlight_type(
t,
{
string = "#98971a",
number = "#458588",
},
"#cc241d"
)
end
-- ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━┓╻ ╻┏━╸┏━╸╺┳╸╻ ╻╻┏━╸╻ ╻
-- ┃ ┣━┫┣╸ ┃┃┃┣╸ ┗━┓┣━┫┣╸ ┣╸ ┃ ┃┏┛┃┣╸ ┃╻┃
-- ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━┛╹ ╹┗━╸┗━╸ ╹ ┗┛ ╹┗━╸┗┻┛
--
-- In this section we are going to style the sheetview.
-- That is the part where the spreadsheet will be showed to you.
--
-- It is important to know that every color value can be ether a
-- color value as described above or a function which returns such kind
-- of value (This applies also to all other kind of values as we will
-- see later in this file).
--
neosheet.config.theme.view.cursor = function(cell)
return {
fg = cell_fg(type(cell.value)),
bg = "#ebdbb2",
bold = true
}
end
-- Let's create a chessboard-pattern for the cells and selection.
-- such that it looks cleaner and we can see the columns and rows better.
neosheet.config.theme.view.cell = function(cell)
local theme = {
fg = cell_fg(type(cell.value))
}
if ((cell.row + cell.column) % 2 == 0) then
theme.bg = "#282828";
else
theme.bg = "#3c3836";
end
return theme
end
neosheet.config.theme.view.selection = function(cell)
local theme = {
fg = cell_fg(type(cell.value)),
}
if ((cell.row + cell.column) % 2 == 0) then
theme.bg = "#665c54";
else
theme.bg = "#504945";
end
return theme
end
-- For the background where no cell is drawn we can also use just a static value.
neosheet.config.theme.view.background = { bg = "#32302f" }
-- ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━┓╻ ╻┏━╸┏━╸╺┳╸╻ ╻╻┏━╸╻ ╻ ┏┓ ┏━┓┏━┓
-- ┃ ┣━┫┣╸ ┃┃┃┣╸ ┗━┓┣━┫┣╸ ┣╸ ┃ ┃┏┛┃┣╸ ┃╻┃ ┣┻┓┣━┫┣┳┛
-- ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━┛╹ ╹┗━╸┗━╸ ╹ ┗┛ ╹┗━╸┗┻┛ ┗━┛╹ ╹╹┗╸
--
-- Now let's style the bar which is attached to the
-- bottom of the sheetview.
--
-- As a side note: Every bar element in neosheet
-- will be styled the same way.
--
neosheet.config.theme.view.bar.left = {
fg = "#ebdbb2",
bg = "#b16286"
}
neosheet.config.theme.view.bar.middle = {
fg = "#ebdbb2",
bg = "#1d2021"
}
-- We can also display the current mode on the left side
-- of the bar with a function.
neosheet.state.view.bar.left = function(mode)
return " " .. string.upper(mode) .. " "
end
neosheet.state.view.bar.middle = " "
-- ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╺┳┓╻╺┳╸┏━┓┏━┓
-- ┃ ┣━┫┣╸ ┃┃┃┣╸ ┣╸ ┃┃┃ ┃ ┃ ┃┣┳┛
-- ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╺┻┛╹ ╹ ┗━┛╹┗╸
--
-- The editor is the part of neosheet were you can
-- edit your more complex formulas and transformation scripts.
--
neosheet.config.theme.editor.background = { bg = "#282828" }
neosheet.config.theme.editor.cursor_line = { bg = "#32302f" }
neosheet.config.theme.editor.line_number = { fg = "#a89984" }
neosheet.config.theme.editor.active_line_number = {
fg = "#a89984", bg = "#504945", bold = true
}
-- ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╺┳┓╻╺┳╸┏━┓┏━┓ ┏┓ ┏━┓┏━┓
-- ┃ ┣━┫┣╸ ┃┃┃┣╸ ┣╸ ┃┃┃ ┃ ┃ ┃┣┳┛ ┣┻┓┣━┫┣┳┛
-- ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╺┻┛╹ ╹ ┗━┛╹┗╸ ┗━┛╹ ╹╹┗╸
--
-- The editor also does have a bar on the bottom.
-- It is styled the same way as we did on sheetview.
--
neosheet.config.theme.editor.bar.left = {
fg = "#ebdbb2",
bg = "#b16286"
}
neosheet.config.theme.editor.bar.middle = {
fg = "#ebdbb2",
bg = "#1d2021"
}
-- ╺┳╸╻ ╻┏━╸┏┳┓┏━╸ ┏━╸╺┳┓╻╺┳╸┏━┓┏━┓ ╻ ╻╻┏━╸╻ ╻╻ ╻┏━╸╻ ╻╺┳╸
-- ┃ ┣━┫┣╸ ┃┃┃┣╸ ┣╸ ┃┃┃ ┃ ┃ ┃┣┳┛ ┣━┫┃┃╺┓┣━┫┃ ┃┃╺┓┣━┫ ┃
-- ╹ ╹ ╹┗━╸╹ ╹┗━╸ ┗━╸╺┻┛╹ ╹ ┗━┛╹┗╸ ╹ ╹╹┗━┛╹ ╹┗━╸╹┗━┛╹ ╹ ╹
--
-- In this section we can set the colors of the syntax highlighting
-- in the editor.
--
neosheet.config.theme.editor.highlight = {
attribute = { fg = "#a89984" },
boolean = { fg = "#690d6a" },
comment = { fg = "#665c54" },
conditional = { fg = "#fabdb2f" },
constant = { fg = "#458588" },
constant_builtin = { fg = "#458588" },
constructor = { fg = "#ebdbb2" },
field = { fg = "#a89984" },
['function'] = { fg = "#ebdbb2" },
function_builtin = { fg = "#ebdbb2" },
function_call = { fg = "#ebdbb2" },
keyword = { fg = "#fabdb2f" },
keyword_function = { fg = "#fabd2f" },
keyword_operator = { fg = "#fabd2f" },
keyword_return = { fg = "#fabd2f" },
label = { fg = "#ebdbb2" },
method = { fg = "#83a598" },
method_call = { fg = "#83a598" },
number = { fg = "#458588" },
operator = { fg = "#a89984" },
parameter = { fg = "#ebdbb2" },
preproc = { fg = "#ebdbb2" },
punctuation_bracket = { fg = "#a89984" },
punctuation_delimiter = { fg = "#a89984" },
['repeat'] = { fg = "#fabdb2f" },
string = { fg = "#8ec07c" },
string_escape = { fg = "#fabdb2f" },
variable = { fg = "#ebdbb2" },
variable_builtin = { fg = "#ebdbb2" },
}
-- ╻┏ ┏━╸╻ ╻┏┳┓┏━┓┏━┓
-- ┣┻┓┣╸ ┗┳┛┃┃┃┣━┫┣━┛
-- ╹ ╹┗━╸ ╹ ╹ ╹╹ ╹╹
--
-- Let's define some keymaps so we can actually navigate
-- in neosheet.
--
-- The keymaps are configured under `neosheet.config.keymap`
-- there is always the `map` function which takes a key-combination
-- and a function as a argument.
--
-- ╻┏ ┏━╸╻ ╻┏┳┓┏━┓┏━┓ ┏━┓╻ ╻┏━╸┏━╸╺┳╸╻ ╻╻┏━╸╻ ╻
-- ┣┻┓┣╸ ┗┳┛┃┃┃┣━┫┣━┛ ┗━┓┣━┫┣╸ ┣╸ ┃ ┃┏┛┃┣╸ ┃╻┃
-- ╹ ╹┗━╸ ╹ ╹ ╹╹ ╹╹ ┗━┛╹ ╹┗━╸┗━╸ ╹ ┗┛ ╹┗━╸┗┻┛
neosheet.config.keymap.view.map('j', function()
neosheet.state.view.move_cursor('down')
end)
neosheet.config.keymap.view.map('k', function()
neosheet.state.view.move_cursor('up')
end)
neosheet.config.keymap.view.map('h', function()
neosheet.state.view.move_cursor('left')
end)
neosheet.config.keymap.view.map('l', function()
neosheet.state.view.move_cursor('right')
end)
neosheet.config.keymap.view.map('<s-h>', function()
neosheet.state.view.move_cursor('begin')
end)
neosheet.config.keymap.view.map('<s-l>', function()
neosheet.state.view.move_cursor('end')
end)
neosheet.config.keymap.view.map('<s-k>', function()
neosheet.state.view.move_cursor('top')
end)
neosheet.config.keymap.view.map('<s-j>', function()
neosheet.state.view.move_cursor('bottom')
end)
neosheet.config.keymap.view.map(':', function()
neosheet.state.view.mode = 'command'
end)
neosheet.config.keymap.view.map('i', function()
neosheet.state.view.mode = 'insert'
end)
neosheet.config.keymap.view.map('v', function()
if (neosheet.state.view.mode == 'visual') then
neosheet.state.view.mode = 'normal'
else
neosheet.state.view.mode = 'visual'
end
end)
neosheet.config.keymap.view.map('s', function()
neosheet.state.active_window = 'editor'
neosheet.state.editor.lines =
[[require('neosheet').state.view.active:map(function(cell)
return ''
end)]]
end)
neosheet.config.keymap.view.map('<esc>', function()
neosheet.state.view.mode = 'normal'
end)
neosheet.config.keymap.global.map('<c-q>', function()
neosheet.state.quit()
end)
neosheet.config.keymap.global.map('<c-l>', function()
neosheet.state.log.visible = not neosheet.state.log.visible
end)
neosheet.config.keymap.global.map('<c-o>', function()
local sheet = neosheet.sheet.open('./sample-large.csv')
neosheet.state.view.active = sheet
end)
-- ╻┏ ┏━╸╻ ╻┏┳┓┏━┓┏━┓ ┏━╸╺┳┓╻╺┳╸┏━┓┏━┓
-- ┣┻┓┣╸ ┗┳┛┃┃┃┣━┫┣━┛ ┣╸ ┃┃┃ ┃ ┃ ┃┣┳┛
-- ╹ ╹┗━╸ ╹ ╹ ╹╹ ╹╹ ┗━╸╺┻┛╹ ╹ ┗━┛╹┗╸
--
-- Let's add vim-motions to the editor.
local mode = nil
local function set_mode(m)
mode = m
if mode == 'normal' then
neosheet.state.editor.cursor_shape = 'block'
neosheet.config.keymap.editor.default = false
elseif mode == 'insert' then
neosheet.state.editor.cursor_shape = 'bar'
neosheet.config.keymap.editor.default = true
end
neosheet.state.editor.bar.left = " "..string.upper(mode).." "
end
set_mode('normal')
neosheet.config.keymap.editor.map('<up>', function()
neosheet.state.editor.move_cursor('up')
end)
neosheet.config.keymap.editor.map('<down>', function()
neosheet.state.editor.move_cursor('down')
end)
neosheet.config.keymap.editor.map('<left>', function()
neosheet.state.editor.move_cursor('left')
end)
neosheet.config.keymap.editor.map('<right>', function()
neosheet.state.editor.move_cursor('right')
end)
neosheet.config.keymap.editor.map('<c-c>', function()
neosheet.state.editor.visible = false;
end)
neosheet.config.keymap.editor.map('<esc>', function()
set_mode('normal')
end)
neosheet.config.keymap.editor.map('i', function()
if mode == 'normal' then
set_mode('insert')
else
return true
end
end)
neosheet.config.keymap.editor.map('a', function()
if mode == 'normal' then
set_mode('insert')
neosheet.state.editor.move_cursor('right')
else
return true
end
end)
neosheet.config.keymap.editor.map('k', function()
if mode == 'normal' then
neosheet.state.editor.move_cursor('up')
else
return true
end
end)
neosheet.config.keymap.editor.map('j', function()
if mode == 'normal' then
neosheet.state.editor.move_cursor('down')
else
return true
end
end)
neosheet.config.keymap.editor.map('h', function()
if mode == 'normal' then
neosheet.state.editor.move_cursor('left')
else
return true
end
end)
neosheet.config.keymap.editor.map('l', function()
if mode == 'normal' then
neosheet.state.editor.move_cursor('right')
else
return true
end
end)
neosheet.config.keymap.editor.map('<c-r>', function()
neosheet.state.editor.run()
end)
|