feat: configure interchangeable top and bottom bars
This commit is contained in:
+69
-56
@@ -12,11 +12,77 @@ module Vamp
|
||||
name
|
||||
end
|
||||
|
||||
# @param value [Hash{String, Symbol => Object}]
|
||||
# @return [Hash{String => Object}]
|
||||
def self.chrome_hash!(value)
|
||||
raise TypeError, "chrome options must be a Hash" unless value.is_a?(Hash)
|
||||
value.each_with_object({}) do |(key, item), result|
|
||||
key = key.to_s if key.is_a?(Symbol)
|
||||
key = string!(key, "chrome key")
|
||||
raise ArgumentError, "duplicate chrome key: #{key}" if result.key?(key)
|
||||
result[key] = item
|
||||
end
|
||||
end
|
||||
|
||||
# @param options [Hash{String, Symbol => Object}]
|
||||
# @return [Hash{String => Object}]
|
||||
def self.chrome_line!(options)
|
||||
chrome_hash!(options).to_h do |name, value|
|
||||
if %w[left center right].include?(name)
|
||||
raise TypeError, "#{name} must be an Array" unless value.is_a?(Array)
|
||||
[name, value.map { |item| chrome_name!(item) }]
|
||||
else
|
||||
chrome_name!(name)
|
||||
style = chrome_hash!(value).to_h do |option, item|
|
||||
case option
|
||||
when "padding"
|
||||
unless item.is_a?(Integer) && item.between?(0, 64)
|
||||
raise ArgumentError, "padding must be an Integer between 0 and 64"
|
||||
end
|
||||
when "title", "leading_edge", "trailing_edge", "first_leading_edge"
|
||||
item = string!(item, option)
|
||||
else
|
||||
raise ArgumentError, "unknown chrome style option: #{option}"
|
||||
end
|
||||
[option, item]
|
||||
end
|
||||
[name, style]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Collects options for the independently configured top and bottom bars.
|
||||
class BarConfig
|
||||
# @return [Hash{String => Object}]
|
||||
attr_reader :top, :bottom
|
||||
|
||||
# @return [void]
|
||||
def initialize
|
||||
@top = {}
|
||||
@bottom = {}
|
||||
end
|
||||
|
||||
# @param options [Hash{String, Symbol => Object}]
|
||||
# @return [Hash{String => Object}]
|
||||
def top=(options)
|
||||
@top = Vamp.chrome_line!(options)
|
||||
end
|
||||
|
||||
# @param options [Hash{String, Symbol => Object}]
|
||||
# @return [Hash{String => Object}]
|
||||
def bottom=(options)
|
||||
@bottom = Vamp.chrome_line!(options)
|
||||
end
|
||||
end
|
||||
|
||||
# Collects and validates the Ruby startup configuration DSL.
|
||||
class Config
|
||||
# @return [Hash{String => Boolean, Hash{String, Symbol => Object}}] language presets/options
|
||||
attr_reader :lsp
|
||||
|
||||
# @return [Vamp::BarConfig]
|
||||
attr_reader :bar
|
||||
|
||||
# @return [void]
|
||||
def initialize
|
||||
@plugins = []
|
||||
@@ -27,8 +93,7 @@ module Vamp
|
||||
@file_picker_view = "tree"
|
||||
@file_explorer_view = "tree"
|
||||
@clipboard_mode = "system"
|
||||
@tabline = {}
|
||||
@statusline = {}
|
||||
@bar = BarConfig.new
|
||||
@labels = {}
|
||||
@diff_context_lines = 10
|
||||
@diff_expand_lines = 15
|
||||
@@ -76,22 +141,10 @@ module Vamp
|
||||
@clipboard_mode = nonempty_string!(mode, "clipboard mode")
|
||||
end
|
||||
|
||||
# @param options [Hash{String, Symbol => Object}]
|
||||
# @return [Hash]
|
||||
def tabline=(options)
|
||||
@tabline = chrome_line!(options)
|
||||
end
|
||||
|
||||
# @param options [Hash{String, Symbol => Object}]
|
||||
# @return [Hash]
|
||||
def statusline=(options)
|
||||
@statusline = chrome_line!(options)
|
||||
end
|
||||
|
||||
# @param values [Hash{String, Symbol => String}]
|
||||
# @return [Hash]
|
||||
def labels=(values)
|
||||
@labels = chrome_hash!(values).to_h do |name, text|
|
||||
@labels = Vamp.chrome_hash!(values).to_h do |name, text|
|
||||
[Vamp.chrome_name!(name), Vamp.string!(text, "label text")]
|
||||
end
|
||||
end
|
||||
@@ -139,51 +192,11 @@ module Vamp
|
||||
{ "version" => 1, "type" => "config", "plugins" => @plugins, "lsp" => lsp_options, "bindings" => @bindings,
|
||||
"leader" => @leader, "file_explorer_side" => @file_explorer_side, "file_picker_view" => @file_picker_view,
|
||||
"file_explorer_view" => @file_explorer_view, "clipboard_mode" => @clipboard_mode,
|
||||
"tabline" => @tabline, "statusline" => @statusline, "labels" => @labels,
|
||||
"top_bar" => @bar.top, "bottom_bar" => @bar.bottom, "labels" => @labels,
|
||||
"diff_context_lines" => @diff_context_lines, "diff_expand_lines" => @diff_expand_lines }
|
||||
end
|
||||
|
||||
private
|
||||
# @param value [Hash{String, Symbol => Object}]
|
||||
# @return [Hash{String => Object}]
|
||||
def chrome_hash!(value)
|
||||
raise TypeError, "chrome options must be a Hash" unless value.is_a?(Hash)
|
||||
value.each_with_object({}) do |(key, item), result|
|
||||
key = key.to_s if key.is_a?(Symbol)
|
||||
key = Vamp.string!(key, "chrome key")
|
||||
raise ArgumentError, "duplicate chrome key: #{key}" if result.key?(key)
|
||||
result[key] = item
|
||||
end
|
||||
end
|
||||
|
||||
# @param options [Hash{String, Symbol => Object}]
|
||||
# @return [Hash{String => Object}]
|
||||
def chrome_line!(options)
|
||||
chrome_hash!(options).to_h do |name, value|
|
||||
if %w[left center right].include?(name)
|
||||
raise TypeError, "#{name} must be an Array" unless value.is_a?(Array)
|
||||
[name, value.map { |item| Vamp.chrome_name!(item) }]
|
||||
else
|
||||
Vamp.chrome_name!(name)
|
||||
style = chrome_hash!(value).to_h do |option, item|
|
||||
case option
|
||||
when "padding"
|
||||
unless item.is_a?(Integer) && item.between?(0, 64)
|
||||
raise ArgumentError, "padding must be an Integer between 0 and 64"
|
||||
end
|
||||
when "title", "leading_edge", "trailing_edge", "first_leading_edge"
|
||||
item = Vamp.string!(item, option)
|
||||
else
|
||||
raise ArgumentError, "unknown chrome style option: #{option}"
|
||||
end
|
||||
[option, item]
|
||||
end
|
||||
[name, style]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# @param value [Integer]
|
||||
# @param label [String]
|
||||
# @param minimum [Integer]
|
||||
|
||||
Reference in New Issue
Block a user