fatty 0.99.12.6 → 0.99.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.org CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
 
15
15
  # gem_docs:version begin
16
- Version: 0.99.12.6
16
+ Version: 0.99.12.7
17
17
  # gem_docs:version end
18
18
 
19
19
  #+TOC: headlines 4
@@ -1379,6 +1379,35 @@ tags:
1379
1379
  #+end_src
1380
1380
 
1381
1381
  ** Key code definitions =keydefs.yml=
1382
+ When =fatty= receives a keycode that it does not know how to name, it
1383
+ sends an alert message that tells what keycode was received and the
1384
+ current terminal name as detected by fatty. You can use that
1385
+ information to give that code a name, including any modifiers, by
1386
+ editing the =keydefs.yml= file as described in this section. Similar
1387
+ information can be found at the top of the =fatty= help message invoked
1388
+ with =M-?=.
1389
+
1390
+ To trace a keypress from curses input through decoding and action selection,
1391
+ enable these debug tags in =config.yml=:
1392
+
1393
+ #+begin_src yaml :tangle no
1394
+ log:
1395
+ level: debug
1396
+ tags:
1397
+ - keycode
1398
+ - keyevent
1399
+ - keybinding
1400
+ #+end_src
1401
+
1402
+ The log records =curses_getch= for individual input values (including escape
1403
+ sequence lookahead), =key_decode= for the assembled input and decoded key,
1404
+ =key_event= after Windows modifier recovery, and =key_binding_context=,
1405
+ =key_binding=, and =key_action= for context lookup and action selection.
1406
+ The decoder includes the terminal name used for =keydefs.yml=. A nil binding
1407
+ is a lookup miss; printable input can still select =self_insert=. Idle polls
1408
+ are omitted. These debug records include typed characters, so enable them
1409
+ when diagnosing input and turn them off afterward.
1410
+
1382
1411
  Most keys are named correctly by curses. Some terminal emulators, multiplexers,
1383
1412
  or keyboard modes emit numeric keycodes that curses does not name usefully.
1384
1413
  The =keydefs.yml= file lets you assign names and modifiers to those numeric
@@ -11,3 +11,8 @@ tmux:
11
11
  572:
12
12
  key: right
13
13
  ctrl: true
14
+
15
+ # Windows console Backspace is BS (8), unlike ncurses KEY_BACKSPACE.
16
+ windows-terminal:
17
+ 8:
18
+ key: backspace
@@ -87,6 +87,16 @@ module Fatty
87
87
  Command.session(:active, :terminal_paste, text: raw.last)
88
88
  elsif (ev = @key_decoder.decode(raw))
89
89
  ev = apply_key_modifiers(ev, raw)
90
+ Fatty.debug(
91
+ :key_event,
92
+ tag: :keyevent,
93
+ raw: raw.inspect,
94
+ key: ev.key,
95
+ text: ev.text.inspect,
96
+ ctrl: ev.ctrl?,
97
+ meta: ev.meta?,
98
+ shift: ev.shift?,
99
+ )
90
100
  if ev.key == :resize
91
101
  Command.terminal(:resize)
92
102
  else
@@ -204,6 +214,8 @@ module Fatty
204
214
  nxt = with_window_timeout(escape_lookahead_ms) { window.getch }
205
215
  return ch if nxt == -1 || !nxt
206
216
 
217
+ log_keycode(nxt)
218
+
207
219
  if csi_prefix?(nxt)
208
220
  suffix = read_escape_suffix
209
221
  seq = "[" + suffix
@@ -221,6 +233,7 @@ module Fatty
221
233
  if suffix == -1 || !suffix
222
234
  [ch, nxt]
223
235
  else
236
+ log_keycode(suffix)
224
237
  [ch, nxt, suffix]
225
238
  end
226
239
  else
@@ -257,8 +270,6 @@ module Fatty
257
270
  end
258
271
 
259
272
  def log_keycode(ch)
260
- return unless Fatty::Config.config.dig(:log, :tags)&.include?(:keycode)
261
-
262
273
  Fatty.debug(
263
274
  :curses_getch,
264
275
  tag: :keycode,
@@ -334,6 +345,7 @@ module Fatty
334
345
  if ch == -1 || !ch
335
346
  done = true
336
347
  else
348
+ log_keycode(ch)
337
349
  char = raw_char_to_s(ch)
338
350
  if char.bytesize != 1 || !char.ord.between?(0x20, 0x7e)
339
351
  push_pending_raw(ch)
@@ -78,7 +78,17 @@ module Fatty
78
78
  else
79
79
  decode_single(raw)
80
80
  end
81
- Fatty.debug("#{self.class}#decode(raw: #{raw}) -> #{result}", tag: :keycode)
81
+ Fatty.debug(
82
+ :key_decode,
83
+ tag: :keycode,
84
+ terminal: env[:terminal],
85
+ raw: raw.inspect,
86
+ key: result&.key,
87
+ text: result&.text.inspect,
88
+ ctrl: result&.ctrl?,
89
+ meta: result&.meta?,
90
+ shift: result&.shift?,
91
+ )
82
92
  result
83
93
  end
84
94
 
@@ -88,6 +98,7 @@ module Fatty
88
98
 
89
99
  def decode_csi(raw)
90
100
  if (spec = @sequence_map["\e[#{raw.last}"])
101
+ Fatty.debug(:keydef_sequence, tag: :keycode, raw: raw.inspect, mapping: spec)
91
102
  return KeyEvent.new(**spec, raw: raw)
92
103
  end
93
104
 
@@ -203,6 +214,7 @@ module Fatty
203
214
  ev
204
215
  end
205
216
  else
217
+ Fatty.debug(:key_decode_fallback, tag: :keycode, raw: ch.inspect)
206
218
  fallback_decode(ch)
207
219
  end
208
220
  end
@@ -140,6 +140,8 @@ module Fatty
140
140
  code = offset + relative
141
141
  [code, KeyEvent.new(**spec, raw: code)]
142
142
  end
143
+ # Preserve ordinary Windows Backspace even without a terminal identity.
144
+ events[8] = KeyEvent.new(key: :backspace, raw: 8)
143
145
  # The Windows backend encodes Shift/Ctrl/Alt F1-F12 as F13-F48.
144
146
  { shift: 12, ctrl: 24, meta: 36 }.each do |modifier, base|
145
147
  (1..12).each do |number|
data/lib/fatty/help.rb CHANGED
@@ -53,10 +53,12 @@ module Fatty
53
53
  File.read(path)
54
54
  end
55
55
 
56
- def self.keybindings(keymap, width: 83)
56
+ def self.keybindings(keymap, width: 83, environment: {})
57
57
  lines = [
58
58
  "# Current keybindings",
59
59
  "",
60
+ environment_summary(environment),
61
+ "",
60
62
  "Fatty is the terminal user-interface library used by this application. " \
61
63
  "It provides command-line editing, output paging and search, and interactive prompts and menus.",
62
64
  "",
@@ -111,6 +113,22 @@ module Fatty
111
113
  [key_width, action_width, [width - 12 - key_width - action_width, 11].max]
112
114
  end
113
115
 
116
+ def self.environment_summary(env)
117
+ terminal = env[:terminal] || "unknown"
118
+ version = env[:terminal_version].to_s
119
+ terminal = "#{terminal} (#{version})" unless version.empty?
120
+ lines = [
121
+ "Terminal: #{terminal}",
122
+ "TERM: #{env[:term].to_s.empty? ? '(unset)' : env[:term]}",
123
+ "Renderer: #{env[:renderer] || 'unknown'}",
124
+ "Curses: #{env[:curses_version] || 'unknown'}",
125
+ "Platform: #{env[:os] || 'unknown'} / #{env[:arch] || 'unknown'}",
126
+ ]
127
+ lines << "SSH: yes" if env[:ssh]
128
+ lines.map { |line| "- #{line}" }.join("\n")
129
+ end
130
+ private_class_method :environment_summary
131
+
114
132
  def self.wrap_cell(text, width)
115
133
  lines = []
116
134
  line = +""
data/lib/fatty/key_map.rb CHANGED
@@ -194,8 +194,7 @@ module Fatty
194
194
 
195
195
  def resolve(event, contexts: [])
196
196
  result = binding_for(event, contexts: contexts)
197
- map_str = "#{event} -> #{result.inspect} in contexts: #{contexts} "
198
- Fatty.debug("KeyMap#resolve: #{map_str}", tag: :keybinding)
197
+ Fatty.debug(:key_binding, tag: :keybinding, key: event.to_s, contexts: contexts, binding: result)
199
198
  result
200
199
  end
201
200
 
@@ -207,18 +206,20 @@ module Fatty
207
206
  if binding.is_a?(Array)
208
207
  action = binding[0]
209
208
  args = binding[1..] || []
210
- Fatty.debug("KeyMap.resolve_action: action: #{action.inspect}, args: #{args.inspect}", tag: :keybinding)
209
+ Fatty.debug(:key_action, tag: :keybinding, key: event.to_s, action: action, args: args)
211
210
  [action, args]
212
211
  else
213
- Fatty.debug("KeyMap.resolve_action: action: #{binding.inspect}, args: []", tag: :keybinding)
212
+ Fatty.debug(:key_action, tag: :keybinding, key: event.to_s, action: binding, args: [])
214
213
  [binding, []]
215
214
  end
216
215
  elsif event&.printable? && (contexts.include?(:text) || contexts.include?(:pager_input))
217
216
  # Default: treat printable characters as a self-insert but only in
218
217
  # those contexts designed to take text input, not contexts like
219
218
  # :paging where keys are meant for control.
219
+ Fatty.debug(:key_action, tag: :keybinding, key: event.to_s, action: :self_insert, args: [event.text])
220
220
  [:self_insert, [event.text]]
221
221
  else
222
+ Fatty.debug(:key_action, tag: :keybinding, key: event.to_s, action: nil, args: [])
222
223
  [nil, []]
223
224
  end
224
225
  end
@@ -275,6 +276,7 @@ module Fatty
275
276
  next unless map
276
277
 
277
278
  result = map[gest]
279
+ Fatty.debug(:key_binding_context, tag: :keybinding, key: event.to_s, context: ctx, binding: result)
278
280
  break if result
279
281
  end
280
282
  result
@@ -30,10 +30,11 @@ module Fatty
30
30
  map.bind(key: :delete, action: :delete_char_forward)
31
31
  map.bind(key: :d, ctrl: true, action: :delete_char_forward)
32
32
  map.bind(key: :backspace, action: :delete_char_backward)
33
- # Some terminals (including Windows) send BS, indistinguishable from C-h.
34
- map.bind(key: :h, ctrl: true, action: :delete_char_backward)
33
+ # Ctrl-Backspace may send BS (8), indistinguishable from C-h.
34
+ map.bind(key: :h, ctrl: true, action: :kill_word_backward)
35
35
  map.bind(key: :h, ctrl: true, meta: true, action: :kill_word_backward)
36
36
  map.bind(key: :backspace, meta: true, action: :kill_word_backward)
37
+ map.bind(key: :backspace, ctrl: true, action: :kill_word_backward)
37
38
  map.bind(key: :w, ctrl: true, action: :kill_word_backward)
38
39
  map.bind(key: :d, meta: true, action: :kill_word_forward)
39
40
  map.bind(key: :k, ctrl: true, action: :kill_to_eol)
@@ -6,7 +6,7 @@ module Fatty
6
6
  super
7
7
  width = [screen.output_rect.cols, 83].min
8
8
  text = Markdown.render(
9
- Help.keybindings(keymap, width: width),
9
+ Help.keybindings(keymap, width: width, environment: help_environment),
10
10
  width: [width, 80].min,
11
11
  table_widths: Help.keybinding_column_widths(width),
12
12
  table_borders: true,
@@ -36,6 +36,15 @@ module Fatty
36
36
 
37
37
  private
38
38
 
39
+ def help_environment
40
+ renderer_name = case terminal.renderer
41
+ when Renderer::Truecolor then "truecolor"
42
+ when Renderer::Curses then "curses"
43
+ else "unknown"
44
+ end
45
+ (terminal.env || {}).merge(renderer: renderer_name, curses_version: ::Curses::VERSION)
46
+ end
47
+
39
48
  def help_role(line)
40
49
  if line == "Current keybindings"
41
50
  :markdown_h1
@@ -404,7 +404,7 @@ module Fatty
404
404
  if ev.uncoded?
405
405
  alert_cmd(
406
406
  :error,
407
- "Undefined key: #{ev.key} " \
407
+ "Undefined key: #{ev.key} (terminal: #{terminal.env&.fetch(:terminal, nil) || 'unknown'}) " \
408
408
  "(edit config in 'keydefs.yml' to name)",
409
409
  ev: ev,
410
410
  )
data/lib/fatty/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Fatty
4
- VERSION = "0.99.12.6"
4
+ VERSION = "0.99.12.7"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fatty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.12.6
4
+ version: 0.99.12.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel E. Doherty
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-11-27 00:00:00.000000000 Z
10
+ date: 2026-11-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: fat_config