Random stuff to do with scripting
This commit is contained in:
8
config/config.json
Normal file
8
config/config.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"startup": "bash $CRIB_CONFIG_DIR/startup.sh",
|
||||
"shutdown": "bash $CRIB_CONFIG_DIR/shutdown.sh",
|
||||
|
||||
"theme": "theme.json",
|
||||
|
||||
"lsp_config": "lsp_config.json"
|
||||
}
|
||||
0
config/lsp_config.json
Normal file
0
config/lsp_config.json
Normal file
151
config/main.rb
Normal file
151
config/main.rb
Normal file
@@ -0,0 +1,151 @@
|
||||
module C
|
||||
attr_accessor :theme, :lsp_config, :languages,
|
||||
:line_endings, :utf_mode, :highlighters
|
||||
attr_reader :b_startup, :b_shutdown, :b_extra_highlights
|
||||
|
||||
@lsp_config = {}
|
||||
@languages = {}
|
||||
@key_handlers = {}
|
||||
@key_binds = {}
|
||||
|
||||
def startup(&block)
|
||||
@b_startup = block
|
||||
end
|
||||
|
||||
def shutdown(&block)
|
||||
@b_shutdown = block
|
||||
end
|
||||
|
||||
def extra_highlights(&block)
|
||||
@b_extra_highlights = block
|
||||
end
|
||||
|
||||
def bind(modes, keys = nil, action = nil, &block)
|
||||
modes = [modes] unless modes.is_a?(Array)
|
||||
if keys.nil?
|
||||
app = self
|
||||
dsl = Object.new
|
||||
dsl.define_singleton_method(:set) do |k, act = nil, &blk|
|
||||
app.bind(modes, k, act, &blk)
|
||||
end
|
||||
dsl.instance_exec(&handler)
|
||||
elsif block_given?
|
||||
keys = [keys] unless keys.is_a?(Array)
|
||||
modes.each do |mode|
|
||||
keys.each do |key|
|
||||
@key_handlers[mode] ||= {}
|
||||
@key_handlers[mode][key] ||= []
|
||||
@key_handlers[mode][key] << block
|
||||
end
|
||||
end
|
||||
elsif action.is_a?(String)
|
||||
keys = [keys] unless keys.is_a?(Array)
|
||||
modes.each do |mode|
|
||||
keys.each do |key|
|
||||
@key_binds[mode] ||= {}
|
||||
@key_binds[mode][key] ||= []
|
||||
@key_binds[mode][key] << action
|
||||
end
|
||||
end
|
||||
else
|
||||
raise ArgumentError("invalid arguments")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# basic configuration
|
||||
|
||||
C.startup do
|
||||
do_something_random_here!
|
||||
end
|
||||
|
||||
C.shutdown do
|
||||
do_something_random_here!
|
||||
end
|
||||
|
||||
# this can be modified by the user during runtime through keybindings
|
||||
# But i need to know how to ever read this value only when needed .
|
||||
# maybe i can write a function that notifies if theme maybe changed then reload
|
||||
C.theme = {
|
||||
# i have a predefined list of keys that can be used here
|
||||
:default => {
|
||||
# here fg bg and style are all optional and have default values
|
||||
# if not specified
|
||||
fg: 0xEEEEEE,
|
||||
bg: 0x000000,
|
||||
italic: false,
|
||||
bold: false,
|
||||
underline: false,
|
||||
strikethrough: false
|
||||
}
|
||||
}
|
||||
|
||||
# this part uses dsl bindings to define the bind function
|
||||
# Hopefully extend to give more context/power to bindings
|
||||
# but try to keep simple for performance
|
||||
# for default keybindings
|
||||
C.bind [:normal, :select], :a => "insert_mode"
|
||||
# for custom keybindings
|
||||
C.bind :select, [:x, :c] do
|
||||
puts "cut"
|
||||
end
|
||||
C.bind :jumper do
|
||||
set [:x, :c] do
|
||||
puts "jump to first bookmark"
|
||||
end
|
||||
end
|
||||
# they can also be defined conditionally
|
||||
# This code is just an example and doesnt actually work
|
||||
if using_tmux?
|
||||
bind :C-p do
|
||||
system("tmux select-pane -U")
|
||||
end
|
||||
end
|
||||
|
||||
# This can for example be modified by user bindings during runtime
|
||||
C.lsp_config[:solargraph] = {
|
||||
command: "solargraph",
|
||||
args: ["stdio"],
|
||||
languages: [:ruby]
|
||||
}
|
||||
|
||||
# these are actually cached into cpp by the editor upon setting
|
||||
C.languages[:ruby] = {
|
||||
color: 0xff8087,
|
||||
symbol: " ",
|
||||
extensions: ["rb"],
|
||||
filenames: ["Gemfile"],
|
||||
mimetypes: ["text/x-ruby"]
|
||||
}
|
||||
|
||||
C.line_endings = :auto_unix # or :auto_windows or :unix or :windows to force
|
||||
C.utf_mode = :auto_utf8 # or :auto_utf16 or :utf8 or :utf16 to force
|
||||
|
||||
C.extra_highlights do |_line, _idx|
|
||||
# the return can be an array of
|
||||
# [fg, bg. flags, start, end]
|
||||
# where fg and bg are integers (using 24 bit color)
|
||||
# and flags is a bitmask of bold/underline/italic etc
|
||||
# and start and end are integers strictly inside the line
|
||||
return []
|
||||
end
|
||||
|
||||
C.highlighters[:language_name] = {
|
||||
parser: ->(_state, _line) {
|
||||
# the return value is an array of
|
||||
# [state, highlights]
|
||||
# state can be of any type but will be consistent between calls
|
||||
# initially nil is sent for uninitialized state
|
||||
# the highlights can be an array of
|
||||
# [fg, bg. flags, start, end]
|
||||
# where fg and bg are integers (using 24 bit color)
|
||||
# and flags is a bitmask of bold/underline/italic etc
|
||||
# and start and end are integers strictly inside the line
|
||||
return []
|
||||
},
|
||||
matcher: ->(_state1, _state2) {
|
||||
# returns true if the states are equal
|
||||
# And so would not need recomputation for further lines
|
||||
return false
|
||||
}
|
||||
}
|
||||
11
config/scripts/shutdown.sh
Normal file
11
config/scripts/shutdown.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# This file can be used to execute commands right after the editor session ends.
|
||||
#
|
||||
# The location of this file is defined in the editor's config.json and can be changed
|
||||
#
|
||||
# It can for example be used to unset environment variables for any lsp(s) used
|
||||
# Or like this example to set kitty padding back higher
|
||||
# kitty @ --to="$KITTY_LISTEN_ON" set-spacing padding=8 margin=0 2>/dev/null || true
|
||||
|
||||
echo "Exiting crib editor..."
|
||||
11
config/scripts/startup.sh
Normal file
11
config/scripts/startup.sh
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# This file can be used to execute commands before the editor session starts.
|
||||
#
|
||||
# The location of this file is defined in the editor's config.json and can be changed
|
||||
#
|
||||
# It can for example be used to set environment variables for any lsp(s) used
|
||||
# Or like this example to set kitty padding to 0
|
||||
# kitty @ --to="$KITTY_LISTEN_ON" set-spacing padding=0 margin=0 2>/dev/null || true
|
||||
|
||||
echo "Starting crib editor..."
|
||||
88
config/theme.json
Normal file
88
config/theme.json
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"Default": {
|
||||
"fg": "#EEEEEE"
|
||||
},
|
||||
"Shebang": {
|
||||
"fg": "#7dcfff"
|
||||
},
|
||||
"Error": {
|
||||
"fg": "#EF5168"
|
||||
},
|
||||
"Comment": {
|
||||
"fg": "#AAAAAA",
|
||||
"italic": true
|
||||
},
|
||||
"String": {
|
||||
"fg": "#AAD94C"
|
||||
},
|
||||
"Escape": {
|
||||
"fg": "#7dcfff"
|
||||
},
|
||||
"Interpolation": {
|
||||
"fg": "#7dcfff"
|
||||
},
|
||||
"Regexp": {
|
||||
"fg": "#D2A6FF"
|
||||
},
|
||||
"Number": {
|
||||
"fg": "#E6C08A"
|
||||
},
|
||||
"True": {
|
||||
"fg": "#7AE93C"
|
||||
},
|
||||
"False": {
|
||||
"fg": "#EF5168"
|
||||
},
|
||||
"Char": {
|
||||
"fg": "#FFAF70"
|
||||
},
|
||||
"Keyword": {
|
||||
"fg": "#FF8F40"
|
||||
},
|
||||
"KeywordOperator": {
|
||||
"fg": "#F07178"
|
||||
},
|
||||
"Operator": {
|
||||
"fg": "#FFFFFF",
|
||||
"italic": true
|
||||
},
|
||||
"Function": {
|
||||
"fg": "#FFAF70"
|
||||
},
|
||||
"Type": {
|
||||
"fg": "#F07178"
|
||||
},
|
||||
"Constant": {
|
||||
"fg": "#7dcfff"
|
||||
},
|
||||
"VariableInstance": {
|
||||
"fg": "#95E6CB"
|
||||
},
|
||||
"VariableGlobal": {
|
||||
"fg": "#F07178"
|
||||
},
|
||||
"Annotation": {
|
||||
"fg": "#7dcfff"
|
||||
},
|
||||
"Directive": {
|
||||
"fg": "#FF8F40"
|
||||
},
|
||||
"Label": {
|
||||
"fg": "#D2A6FF"
|
||||
},
|
||||
"Brace1": {
|
||||
"fg": "#D2A6FF"
|
||||
},
|
||||
"Brace2": {
|
||||
"fg": "#FFAFAF"
|
||||
},
|
||||
"Brace3": {
|
||||
"fg": "#FFFF00"
|
||||
},
|
||||
"Brace4": {
|
||||
"fg": "#0FFF0F"
|
||||
},
|
||||
"Brace5": {
|
||||
"fg": "#FF0F0F"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user