hiiro 0.1.392 → 0.1.393

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad2d60d5740dd8e55e05cb747b2bd6b5e29a04e0afea78044d27b8bd07d89d4b
4
- data.tar.gz: edbb5719e7e2e7fca15751c62140f1c1ef8eb25f62d52a8d3e4d9369e86d400c
3
+ metadata.gz: ead58a6f2c9467256f546afcf8ef417f755717c6f6c346a31f7ae44290fd9d44
4
+ data.tar.gz: c5d4759a675c8f464bc8c6efda43e24abeb8945ef782ca7890365f3bfadbd66a
5
5
  SHA512:
6
- metadata.gz: 3b77ec5fd8c0035039f265df261e982d7e02d730292fdf91196322cce5dba1ce66683e058cbd5816c02d1dc9f5cb1392e32ff8a4638f3766413b8ed28f57db75
7
- data.tar.gz: 1dfc40943e3a3dcd494eae3f0f9ca642b4cbf926db55a5a64ff256003a1fc7b2bb556677c47cdb1b0a2058b8fab42c836424e6b363cf586cae76e6b8190805f5
6
+ metadata.gz: db0fca7b6671893efcb5d6636c49b87cdca6ef0af063ef27be6cb67e1b6b02c5bd36646499adbcdad6b9318a489c51fd6fa8765b3868b7d490b09634442110c8
7
+ data.tar.gz: 6eb79e4d02b4ce0c2d3bf50770b0ed5ad8410ad035d90ae27f5df85039ded7d3491c3ee0e355a92680219ec73825c6cff531dae858d5634608012248aa304a6b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.393] - 2026-10-12
4
+
5
+ ### Added
6
+ - `h json` subcommand (`bin/h-json`)
7
+
3
8
  ## [0.1.392] - 2026-10-12
4
9
 
5
10
  ### Changed
@@ -24,6 +29,9 @@
24
29
 
25
30
  ## Unreleased
26
31
 
32
+ ### Changed
33
+ - `h strip ctrl` replaces bare `h strip` for stripping ASCII terminal escapes and C0/DEL controls from files, stdin, or text. Tabs, line feeds, UTF-8 text, and raw invalid bytes are preserved.
34
+
27
35
  ### Fixed
28
36
  - Fix `PsProcess::Snapshot.capture` constant lookup, which raised `NameError` in `h ps byport`, `h ps indir`, and parent/child process lookups.
29
37
 
data/README.md CHANGED
@@ -123,6 +123,23 @@ printf '%s\n' '"src/my file.rb:12:3"' | h extract files --no-check
123
123
  printf '%s\n' 'missing/output/' | h extract dirs --no-check
124
124
  ```
125
125
 
126
+ ### Strip terminal escapes and controls
127
+
128
+ `h strip ctrl` removes terminal escape sequences and control characters from
129
+ files, piped stdin, or literal text. Tabs, newlines, and UTF-8 text are preserved.
130
+
131
+ ```sh
132
+ h strip ctrl terminal.log > clean.log
133
+ printf '\033[31mhello\033[0m\n' | h strip ctrl
134
+ h strip ctrl hello world
135
+ h strip ctrl --help
136
+ ```
137
+
138
+ The command writes to stdout without adding a newline and reads the whole input
139
+ into memory. Redirect to a different file, not the input file. The command does
140
+ not reconstruct a terminal screen. See [the strip reference](docs/h-misc.md#h-strip-ctrl)
141
+ for input selection and supported escape sequences.
142
+
126
143
  ### Task CLI
127
144
 
128
145
  `t` and `tt` are gem executables in `exe/`, installed alongside `h`. They are thin
@@ -230,6 +247,7 @@ See the [task command reference](docs/t.md) for all commands and the [workflow i
230
247
  | `h run` | Run dev tools (lint/test/format) against changed files |
231
248
  | `h session` | Compatibility commands for Herdr workspaces |
232
249
  | `h sha` | Extract short SHA from git log |
250
+ | [`h strip ctrl`](docs/h-misc.md#h-strip-ctrl) | Strip terminal escapes and controls from files, stdin, or text |
233
251
  | [`h table`](docs/h-table.md) | TUI and scriptable CLI over registry tables (links, sounds, pins, ...) with task scope, tags, and per-table actions |
234
252
  | `h todo` | Todo list management with tags and task association |
235
253
  | `h window` | Compatibility commands for Herdr tabs |
data/bin/h-json ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hiiro'
4
+
5
+ Hiiro.run do
6
+ add_cmd :structure, args: ['[FILE...]'] do
7
+ if opts.args.empty? && $stdin.tty?
8
+ abort 'Usage: h-json structure [FILE...] (or pipe JSON into stdin)'
9
+ end
10
+
11
+ filter = <<~JQ
12
+ def structure:
13
+ if type == "object" then
14
+ with_entries(.value |= structure)
15
+ elif type == "array" then
16
+ map(structure) | unique
17
+ else
18
+ type
19
+ end;
20
+
21
+ structure
22
+ JQ
23
+
24
+ exec('jq', '--', filter, *opts.args)
25
+ rescue Errno::ENOENT
26
+ abort 'h-json structure requires jq on PATH'
27
+ end
28
+ end
data/bin/h-strip CHANGED
@@ -1,39 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- USAGE = <<~TEXT
4
- Usage:
5
- command | h strip
6
- h strip TEXT...
7
- h strip FILE...
8
-
9
- Removes ANSI escape sequences and control characters, preserving tabs and newlines.
10
- Existing file arguments are concatenated; other arguments are joined with spaces.
11
- TEXT
3
+ require 'hiiro'
12
4
 
13
5
  ANSI = /
14
6
  (?:
15
- (?:\x1B\[|\x9B)[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E] |
16
- (?:\x1B\]|\x9D)[^\x07\x1B\x9C]*(?:\x07|\x1B\\|\x9C) |
17
- (?:\x1B[P^_]|[\x90\x98\x9E\x9F])[^\x1B\x9C]*(?:\x1B\\|\x9C) |
7
+ \x1B\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E] |
8
+ \x1B\][^\x07\x1B]*(?:\x07|\x1B\\) |
9
+ \x1B[P^_][^\x1B]*(?:\x1B\\) |
18
10
  \x1B[\x20-\x2F]*[\x30-\x7E]
19
11
  )
20
12
  /nx
21
- CONTROL = /[\x00-\x08\x0B-\x1F\x7F-\x9F]/n
22
-
23
- def input_bytes(arguments)
24
- if arguments.empty?
25
- abort USAGE if STDIN.tty?
26
- return STDIN.binmode.read
27
- end
13
+ CONTROL = /[\x00-\x08\x0B-\x1F\x7F]/n
28
14
 
29
- paths = arguments.map { |argument| File.expand_path(argument) }
30
- return paths.map { |path| File.binread(path) }.join if paths.all? { |path| File.file?(path) }
15
+ Hiiro.run do
16
+ add_cmd :ctrl, args: ['[FILE...|TEXT...]'] do
17
+ arguments = opts.args
18
+ paths = arguments.map { |argument| File.expand_path(argument) }
19
+ input = if arguments.empty? || paths.all? { |path| File.file?(path) }
20
+ Hiiro::Shell.read_input(*paths)
21
+ else
22
+ arguments.join(' ')
23
+ end
31
24
 
32
- arguments.join(' ')
33
- end
34
-
35
- if %w[-h --help help].include?(ARGV.first)
36
- puts USAGE
37
- exit
25
+ STDOUT.binmode.write(input.b.gsub(ANSI, '').gsub(CONTROL, ''))
26
+ nil
27
+ end
38
28
  end
39
- STDOUT.binmode.write(input_bytes(ARGV).gsub(ANSI, '').gsub(CONTROL, ''))
data/docs/h-misc.md CHANGED
@@ -30,3 +30,43 @@ Walk one or more directories and list all symlinks whose destinations fall outsi
30
30
  h misc symlink_destinations packages/
31
31
  h misc symlink_destinations packages/ apps/ --root /path/to/repo
32
32
  ```
33
+
34
+ ## h strip ctrl
35
+
36
+ `h strip ctrl` is a separate external command, not an `h misc` subcommand. It
37
+ removes terminal escape sequences and control characters from input bytes.
38
+
39
+ ```bash
40
+ h strip ctrl FILE...
41
+ command | h strip ctrl
42
+ h strip ctrl TEXT...
43
+ h strip ctrl --help
44
+ ```
45
+
46
+ When every argument names an existing file, the command concatenates their bytes
47
+ in argument order, without separators. Otherwise, it treats all arguments as
48
+ literal text and joins them with spaces. With no arguments, it reads piped stdin.
49
+
50
+ Output goes to stdout without an added newline. Tabs, line feeds, UTF-8 text, and
51
+ raw invalid bytes are preserved. The command removes:
52
+
53
+ - ASCII ESC sequences, including CSI color, cursor, and erase commands.
54
+ - OSC sequences terminated by BEL or ESC followed by a backslash.
55
+ - DCS, APC, and PM sequences terminated by ESC followed by a backslash.
56
+ - C0 controls and DEL, except tab and line feed.
57
+
58
+ Bytes from `0x80` through `0x9F` are not interpreted as C1 terminal controls.
59
+ Stripping does not reconstruct a terminal screen or apply cursor movements.
60
+ The command reads the whole input into memory.
61
+
62
+ ### Examples
63
+
64
+ ```bash
65
+ h strip ctrl terminal.log > clean.log
66
+ h strip ctrl first.log second.log > combined-clean.log
67
+ printf '\033[31mhello\033[0m\n' | h strip ctrl
68
+ h strip ctrl $'\033[31mhello\033[0m' world
69
+ ```
70
+
71
+ Redirect to a different file. Redirecting stdout to an input file truncates that
72
+ file before the command reads it.
data/lib/hiiro/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class Hiiro
2
- VERSION = "0.1.392"
2
+ VERSION = "0.1.393"
3
3
  SUPPORTED_RUBY_VERSION = ">= 3.2.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiiro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.392
4
+ version: 0.1.393
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Toyota
@@ -176,6 +176,7 @@ files:
176
176
  - bin/h-html
177
177
  - bin/h-img
178
178
  - bin/h-js
179
+ - bin/h-json
179
180
  - bin/h-jsonl
180
181
  - bin/h-jumplist
181
182
  - bin/h-link