Class: Omaship::ColorPicker

Inherits:
Object
  • Object
show all
Includes:
LinearPickerControls
Defined in:
lib/omaship/color_picker.rb

Constant Summary collapse

SCHEMES =
[
  { key: "flexoki-light",    bg: "#FFFCF0", primary: "#205EA6", accent: "#AD8301", text: "#100F0F" },
  { key: "flexoki-dark",     bg: "#100F0F", primary: "#4385BE", accent: "#D0A215", text: "#FFFCF0" },
  { key: "catppuccin-latte", bg: "#EFF1F5", primary: "#8839EF", accent: "#179299", text: "#4C4F69" },
  { key: "catppuccin-mocha", bg: "#1E1E2E", primary: "#CBA6F7", accent: "#94E2D5", text: "#CDD6F4" },
  { key: "rosepine-dawn",    bg: "#FAF4ED", primary: "#907AA9", accent: "#D7827E", text: "#575279" },
  { key: "rosepine-moon",    bg: "#232136", primary: "#C4A7E7", accent: "#EA9A97", text: "#E0DEF4" },
  { key: "nord-snow",        bg: "#ECEFF4", primary: "#5E81AC", accent: "#88C0D0", text: "#2E3440" },
  { key: "nord-frost",       bg: "#2E3440", primary: "#88C0D0", accent: "#5E81AC", text: "#ECEFF4" },
  { key: "mono-light",       bg: "#FFFFFF", primary: "#18181B", accent: "#71717A", text: "#18181B" },
  { key: "mono-dark",        bg: "#18181B", primary: "#FAFAFA", accent: "#A1A1AA", text: "#FAFAFA" },
  { key: "solarized-light",  bg: "#FDF6E3", primary: "#268BD2", accent: "#2AA198", text: "#657B83" },
  { key: "solarized-dark",   bg: "#002B36", primary: "#268BD2", accent: "#2AA198", text: "#839496" }
].freeze
DEFAULT_INDEX =
9
SWATCH_SURFACE =
"#FFFFFF"
SWATCH_BORDER =
"#000000"

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, input: $stdin) ⇒ ColorPicker

Returns a new instance of ColorPicker.



26
27
28
29
30
# File 'lib/omaship/color_picker.rb', line 26

def initialize(out: $stdout, input: $stdin)
  @out = out
  @input = input
  @index = DEFAULT_INDEX
end

Instance Method Details

#pickObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/omaship/color_picker.rb', line 32

def pick
  render
  loop do
    key = read_linear_navigation_key(@input)
    case key
    when :previous
      @index = (@index - 1) % SCHEMES.size
      render
    when :next
      @index = (@index + 1) % SCHEMES.size
      render
    when :enter, "q"
      return SCHEMES[@index][:key]
    when :ctrl_c
      raise Interrupt
    end
  end
ensure
  @out.print "\e[?25h"
  @out.puts if @rendered_lines
end