Module: EasyCreds::Theme
- Defined in:
- lib/easy_creds/theme.rb
Constant Summary collapse
- BANNER_ART =
Calvin S figlet — “easy_creds” in 3 rows × 29 cols
[ '┌─┐┌─┐┌─┐┬ ┬ ┌─┐┬─┐┌─┐ ┬ ┌─┐', '├─ ├─┤└─┐└┬┘ │ ├┬ ├─ ┌─┤└─┐', '└─┘└─┘└─┘ ┴ └─┘┴ └─┘└─┘└─┘' ].freeze
- ICONS =
{ ok: '✔', warn: '⚠', error: '✖', info: 'ℹ', push: '↑', pull: '↓', modified: '⇅', added: '↗', removed: '↙', lock: '⚙', vault: '▪', key: '◆', sync: '↔' }.freeze
- SPINNERS =
%w[⠋ ⠙ ⠸ ⠴ ⠦ ⠧ ⠇ ⠏].freeze
Class Method Summary collapse
-
.accent(str) ⇒ Object
#7aa2ff blue.
- .banner(vault, envs) ⇒ Object
- .bold(str) ⇒ Object
- .box_bottom(width) ⇒ Object
- .box_h(width) ⇒ Object
- .box_side ⇒ Object
-
.box_top(width) ⇒ Object
── Rounded box-drawing helpers ────────────────────────────────────────.
- .change_color(kind) ⇒ Object
- .dim(str) ⇒ Object
- .env_tag(str) ⇒ Object
-
.error(str) ⇒ Object
#ff7a8b red.
- .failure(msg) ⇒ Object
- .header(str) ⇒ Object
- .info(str) ⇒ Object
-
.kbd(key) ⇒ Object
Kbd-cap key hint: [k] desc.
- .key_tag(str) ⇒ Object
- .notice(msg) ⇒ Object
-
.ok(str) ⇒ Object
24-bit true-color helpers — Midnight design system.
- .pastel ⇒ Object
- .rpad(str, width) ⇒ Object
- .section(title) ⇒ Object
- .strip_ansi(str) ⇒ Object
- .success(msg) ⇒ Object
-
.title_bar(env_label, width, status: nil) ⇒ Object
Traffic-light title bar: ● ● ● title status.
-
.tprompt_line ⇒ Object
Shell-prompt line: user@host ~/cwd [git-branch].
-
.warn(str) ⇒ Object
#f5cf7b amber.
- .warning(msg) ⇒ Object
Class Method Details
.accent(str) ⇒ Object
#7aa2ff blue
43 |
# File 'lib/easy_creds/theme.rb', line 43 def accent(str) = "\e[38;2;122;162;255m#{str}\e[0m" # #7aa2ff blue |
.banner(vault, envs) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/easy_creds/theme.rb', line 82 def (vault, envs) width = [TTY::Screen.width, 78].min inner_w = width - 4 # '│ ' on left + ' │' on right lines = [ " #{header("#{ICONS[:lock]} easy_creds")} #{dim('credentials ↔ 1Password sync')}", '', " #{dim('vault')} #{vault ? bold(vault) : dim('(not set)')}", " #{dim('envs')} #{envs.any? ? envs.map { |e| env_tag(e) }.join(dim(' · ')) : dim('—')}" ] rows = lines.map { |l| "#{box_side} #{rpad(l, inner_w)} #{box_side}" } ([box_top(width)] + rows + [box_bottom(width)]).join("\n") end |
.bold(str) ⇒ Object
46 |
# File 'lib/easy_creds/theme.rb', line 46 def bold(str) = pastel.bold(str) |
.box_bottom(width) ⇒ Object
61 |
# File 'lib/easy_creds/theme.rb', line 61 def box_bottom(width) = dim("╰#{'─' * [width - 2, 0].max}╯") |
.box_h(width) ⇒ Object
62 |
# File 'lib/easy_creds/theme.rb', line 62 def box_h(width) = dim('─' * width) |
.box_side ⇒ Object
63 |
# File 'lib/easy_creds/theme.rb', line 63 def box_side = dim('│') |
.box_top(width) ⇒ Object
── Rounded box-drawing helpers ────────────────────────────────────────
60 |
# File 'lib/easy_creds/theme.rb', line 60 def box_top(width) = dim("╭#{'─' * [width - 2, 0].max}╮") |
.change_color(kind) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/easy_creds/theme.rb', line 51 def change_color(kind) case kind when :added then ok(ICONS[:added]) when :removed then error(ICONS[:removed]) when :modified then warn(ICONS[:modified]) end end |
.dim(str) ⇒ Object
45 |
# File 'lib/easy_creds/theme.rb', line 45 def dim(str) = pastel.dim(str) |
.env_tag(str) ⇒ Object
48 |
# File 'lib/easy_creds/theme.rb', line 48 def env_tag(str) = accent(str) |
.error(str) ⇒ Object
#ff7a8b red
42 |
# File 'lib/easy_creds/theme.rb', line 42 def error(str) = "\e[38;2;255;122;139m#{str}\e[0m" # #ff7a8b red |
.failure(msg) ⇒ Object
117 |
# File 'lib/easy_creds/theme.rb', line 117 def failure(msg) = puts(" #{error(ICONS[:error])} #{msg}") |
.header(str) ⇒ Object
47 |
# File 'lib/easy_creds/theme.rb', line 47 def header(str) = "\e[1m\e[38;2;122;162;255m#{str}\e[0m" |
.info(str) ⇒ Object
44 |
# File 'lib/easy_creds/theme.rb', line 44 def info(str) = accent(str) |
.kbd(key) ⇒ Object
Kbd-cap key hint: [k] desc
66 |
# File 'lib/easy_creds/theme.rb', line 66 def kbd(key) = "#{dim('[')}" + accent(key) + "#{dim(']')}" |
.key_tag(str) ⇒ Object
49 |
# File 'lib/easy_creds/theme.rb', line 49 def key_tag(str) = accent(str) |
.notice(msg) ⇒ Object
118 |
# File 'lib/easy_creds/theme.rb', line 118 def notice(msg) = puts(" #{accent(ICONS[:info])} #{msg}") |
.ok(str) ⇒ Object
24-bit true-color helpers — Midnight design system
40 |
# File 'lib/easy_creds/theme.rb', line 40 def ok(str) = "\e[38;2;140;227;156m#{str}\e[0m" # #8ce39c green |
.pastel ⇒ Object
35 36 37 |
# File 'lib/easy_creds/theme.rb', line 35 def pastel @pastel ||= Pastel.new end |
.rpad(str, width) ⇒ Object
125 126 127 |
# File 'lib/easy_creds/theme.rb', line 125 def rpad(str, width) str + (' ' * [width - strip_ansi(str).length, 0].max) end |
.section(title) ⇒ Object
97 98 99 100 101 |
# File 'lib/easy_creds/theme.rb', line 97 def section(title) puts '' puts bold(title) puts dim('─' * [TTY::Screen.width, 60].min) end |
.strip_ansi(str) ⇒ Object
121 122 123 |
# File 'lib/easy_creds/theme.rb', line 121 def strip_ansi(str) str.gsub(/\e\[[0-9;]*[mJHABCDsuK]/, '') end |
.success(msg) ⇒ Object
116 |
# File 'lib/easy_creds/theme.rb', line 116 def success(msg) = puts(" #{ok(ICONS[:ok])} #{msg}") |
.title_bar(env_label, width, status: nil) ⇒ Object
Traffic-light title bar: ● ● ● title status
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/easy_creds/theme.rb', line 69 def (env_label, width, status: nil) lights = "#{error('●')} #{warn('●')} #{ok('●')}" lights_vis = 5 right_str = status ? dim(status) : '' right_vis = status ? strip_ansi(right_str).length : 0 title_str = "\e[1m\e[38;2;122;162;255m#{env_label}\e[0m" title_vis = env_label.length pad_total = [width - lights_vis - 2 - right_vis - title_vis - 2, 0].max pad_left = pad_total / 2 pad_right = pad_total - pad_left " #{lights}#{' ' * pad_left}#{title_str}#{' ' * pad_right}#{right_str}" end |
.tprompt_line ⇒ Object
Shell-prompt line: user@host ~/cwd [git-branch]
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/easy_creds/theme.rb', line 104 def tprompt_line user = ENV.fetch('USER', ENV.fetch('USERNAME', 'user')) host = ENV.fetch('HOSTNAME', `hostname -s 2>/dev/null`.strip) host = host.split('.').first host = 'localhost' if host.to_s.empty? cwd = Dir.pwd.gsub(Dir.home, '~') branch = `git rev-parse --abbrev-ref HEAD 2>/dev/null`.strip out = "#{ok(user)}#{dim('@')}#{accent(host)} #{dim(cwd)}" out += " #{dim("[#{branch}]")}" unless branch.empty? out end |
.warn(str) ⇒ Object
#f5cf7b amber
41 |
# File 'lib/easy_creds/theme.rb', line 41 def warn(str) = "\e[38;2;245;207;123m#{str}\e[0m" # #f5cf7b amber |
.warning(msg) ⇒ Object
119 |
# File 'lib/easy_creds/theme.rb', line 119 def warning(msg) = puts(" #{warn(ICONS[:warn])} #{msg}") |