sight 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 05abdb72bec3313b413b826f36a5f5a5590374d7d61640460a41eddd75a57ab6
4
+ data.tar.gz: 27d5fb5d877eebf0152ffa070201e2bb0755256cb466027bc3f61c26bccd4a16
5
+ SHA512:
6
+ metadata.gz: 41a607fda53ab9822d968c8d2af280b71db14bb3edf96752dfd8ce26450277d44e19ad85f1677940506b75f80503f6511201291795d031d42aab10beb598bbe5
7
+ data.tar.gz: 254d6c49a5abb2ead9130daad53fc874523a282b1b69c50b9df0f015280ea7fb47ff8a099f3b21badd10b074c0b39941749c7b200f913a358a7e6635029954dd
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-03-04
4
+
5
+ ### Added
6
+
7
+ - Interactive curses-based TUI for browsing git diffs
8
+ - Color-coded add/delete/context lines with line-number gutter
9
+ - Vim-style keybindings for scrolling and navigation
10
+ - Per-file navigation with `n`/`p` keys
11
+ - Help overlay with `?`
12
+ - Fallback to `--cached` diff for initial commits
13
+ - CLI with `--help` and `--version` flags
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "sight" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["arzezak@gmail.com"](mailto:"arzezak@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Ariel Rzezak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Sight
2
+
3
+ Terminal UI for browsing git diffs interactively with colors, scrolling, and file navigation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install sight
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Stage some changes (or have unstaged changes), then run:
14
+
15
+ ```bash
16
+ sight
17
+ ```
18
+
19
+ ### Keybindings
20
+
21
+ | Key | Action |
22
+ |-----|--------|
23
+ | `j` / `↓` | Scroll down |
24
+ | `k` / `↑` | Scroll up |
25
+ | `d` | Half page down |
26
+ | `u` | Half page up |
27
+ | `f` | Full page down |
28
+ | `b` | Full page up |
29
+ | `g` | Go to top |
30
+ | `G` | Go to bottom |
31
+ | `n` / `→` | Next file |
32
+ | `p` / `←` | Previous file |
33
+ | `?` | Toggle help |
34
+ | `q` / `Esc` | Quit |
35
+
36
+ ## Development
37
+
38
+ ```bash
39
+ bin/setup
40
+ rake test
41
+ bundle exec standardrb
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/arzezak/sight. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/arzezak/sight/blob/main/CODE_OF_CONDUCT.md).
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+
52
+ ## Code of Conduct
53
+
54
+ Everyone interacting in the Sight project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/arzezak/sight/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
data/exe/sight ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
6
+
7
+ require "sight"
8
+
9
+ Sight::CLI.run(ARGV)
data/lib/sight/app.rb ADDED
@@ -0,0 +1,211 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "curses"
4
+
5
+ module Sight
6
+ class App
7
+ attr_reader :files, :file_lines
8
+ attr_accessor :file_idx, :offset
9
+
10
+ def initialize(files)
11
+ @files = files
12
+ @file_lines = files.map { build_file_lines(it) }
13
+ @file_idx = 0
14
+ @offset = 0
15
+ end
16
+
17
+ def run
18
+ init_curses
19
+
20
+ loop do
21
+ render
22
+
23
+ break unless handle_input
24
+ end
25
+ ensure
26
+ Curses.close_screen
27
+ end
28
+
29
+ private
30
+
31
+ def build_file_lines(file)
32
+ file.hunks.flat_map do |hunk|
33
+ hunk.lines.map do |diff_line|
34
+ text = (diff_line.type == :meta) ? diff_line.content : diff_line.content[1..]
35
+ DisplayLine.new(type: diff_line.type, text: text, lineno: diff_line.lineno)
36
+ end
37
+ end
38
+ end
39
+
40
+ def init_curses
41
+ Curses.init_screen
42
+ Curses.start_color
43
+ Curses.use_default_colors
44
+ Curses.cbreak
45
+ Curses.noecho
46
+ Curses.curs_set(0)
47
+ Curses.stdscr.keypad(true)
48
+ Curses.init_pair(1, Curses::COLOR_GREEN, -1)
49
+ Curses.init_pair(2, Curses::COLOR_RED, -1)
50
+ Curses.init_pair(3, Curses::COLOR_CYAN, -1)
51
+ Curses.init_pair(4, Curses::COLOR_YELLOW, -1)
52
+ end
53
+
54
+ def lines
55
+ file_lines[file_idx]
56
+ end
57
+
58
+ def render
59
+ win = Curses.stdscr
60
+ win.clear
61
+ width = Curses.cols
62
+ render_header(win, width)
63
+ render_content(win, width)
64
+ render_status_bar(win, width)
65
+ win.refresh
66
+ end
67
+
68
+ def render_header(win, width)
69
+ path = files[file_idx].path
70
+ win.setpos(0, 0)
71
+ win.attron(color_for(:header)) { win.addstr(path[0, width]) }
72
+ win.setpos(1, 0)
73
+ win.attron(color_for(:header)) { win.addstr("\u2500" * width) }
74
+ end
75
+
76
+ def render_content(win, width)
77
+ gutter = gutter_width
78
+ dim = Curses.color_pair(0) | Curses::A_DIM
79
+ content_width = width - gutter - 3
80
+
81
+ scroll_height.times do |row|
82
+ idx = offset + row
83
+ break if idx >= lines.size
84
+ line = lines[idx]
85
+ win.setpos(row + 2, 0)
86
+ win.attron(dim) { win.addstr("#{format_gutter(line.type, line.lineno, gutter)} │ ") }
87
+ win.attron(color_for(line.type)) { win.addstr(line.text[0, content_width]) }
88
+ end
89
+ end
90
+
91
+ def render_status_bar(win, width)
92
+ win.setpos(Curses.lines - 1, 0)
93
+ win.attron(Curses.color_pair(4) | Curses::A_REVERSE) do
94
+ status = " File #{file_idx + 1}/#{files.size} | Line #{offset + 1}/#{lines.size} "
95
+ win.addstr(status.ljust(width))
96
+ end
97
+ end
98
+
99
+ def format_gutter(type, lineno, width)
100
+ if lineno
101
+ lineno.to_s.rjust(width)
102
+ elsif type == :del
103
+ "~".rjust(width)
104
+ else
105
+ " " * width
106
+ end
107
+ end
108
+
109
+ def color_for(type)
110
+ case type
111
+ when :add then Curses.color_pair(1)
112
+ when :del then Curses.color_pair(2)
113
+ when :header then Curses.color_pair(4) | Curses::A_BOLD
114
+ else Curses.color_pair(0)
115
+ end
116
+ end
117
+
118
+ def scroll_height
119
+ Curses.lines - 3
120
+ end
121
+
122
+ def gutter_width
123
+ @gutter_width ||= begin
124
+ max = file_lines.flat_map { |file| file.filter_map { |line| line.lineno } }.max || 1
125
+ max.to_s.length
126
+ end
127
+ end
128
+
129
+ def scroll_to(delta)
130
+ max = [0, lines.size - scroll_height].max
131
+ self.offset = (offset + delta).clamp(0, max)
132
+ end
133
+
134
+ def handle_input
135
+ key = Curses.getch
136
+ case key
137
+ when "q", 27 then return false
138
+ when "j", Curses::KEY_DOWN then scroll_to(1)
139
+ when "k", Curses::KEY_UP then scroll_to(-1)
140
+ when "f" then scroll_to(scroll_height)
141
+ when "b" then scroll_to(-scroll_height)
142
+ when "d" then scroll_to(scroll_height / 2)
143
+ when "u" then scroll_to(-scroll_height / 2)
144
+ when "g" then self.offset = 0
145
+ when "G" then scroll_to(lines.size)
146
+ when "n", Curses::KEY_RIGHT then jump_file(1)
147
+ when "p", Curses::KEY_LEFT then jump_file(-1)
148
+ when "?" then show_help
149
+ end
150
+ true
151
+ end
152
+
153
+ HELP_KEYS = [
154
+ ["j / ↓", "Scroll down"],
155
+ ["k / ↑", "Scroll up"],
156
+ ["d", "Half Page down"],
157
+ ["u", "Half page up"],
158
+ ["f", "Full page down"],
159
+ ["b", "Full page up"],
160
+ ["g", "Go to top"],
161
+ ["G", "Go to bottom"],
162
+ ["n / →", "Next file"],
163
+ ["p / ←", "Previous file"],
164
+ ["q / Esc", "Quit"],
165
+ ["?", "Toggle this help"]
166
+ ].freeze
167
+
168
+ KEY_W = HELP_KEYS.map { |k, _| k.length }.max
169
+ HELP_LINES = HELP_KEYS.map { |k, desc| "#{k.ljust(KEY_W)} #{desc}" }.freeze
170
+ HELP_WIDTH = HELP_LINES.map(&:length).max + 6
171
+ HELP_HEIGHT = HELP_LINES.size + 4
172
+
173
+ def show_help
174
+ win = Curses.stdscr
175
+ top = (Curses.lines - HELP_HEIGHT) / 2
176
+ left = (Curses.cols - HELP_WIDTH) / 2
177
+ draw_box(win, top, left, HELP_WIDTH, HELP_HEIGHT, "Keybindings", HELP_LINES)
178
+ win.refresh
179
+ Curses.getch
180
+ end
181
+
182
+ def draw_box(win, top, left, width, height, title, content_lines)
183
+ win.attron(Curses.color_pair(0)) do
184
+ win.setpos(top, left)
185
+ win.addstr("┌#{"─" * (width - 2)}┐")
186
+
187
+ win.setpos(top + 1, left)
188
+ pad = width - 2 - title.length
189
+ win.addstr("│#{" " * (pad / 2)}#{title}#{" " * (pad - pad / 2)}│")
190
+
191
+ win.setpos(top + 2, left)
192
+ win.addstr("├#{"─" * (width - 2)}┤")
193
+
194
+ content_lines.each_with_index do |line, i|
195
+ win.setpos(top + 3 + i, left)
196
+ win.addstr("│ #{line.ljust(width - 5)} │")
197
+ end
198
+
199
+ win.setpos(top + height - 1, left)
200
+ win.addstr("└#{"─" * (width - 2)}┘")
201
+ end
202
+ end
203
+
204
+ def jump_file(direction)
205
+ new_idx = (file_idx + direction).clamp(0, files.size - 1)
206
+ return if new_idx == file_idx
207
+ self.file_idx = new_idx
208
+ self.offset = 0
209
+ end
210
+ end
211
+ end
data/lib/sight/cli.rb ADDED
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sight
4
+ module CLI
5
+ module_function
6
+
7
+ def run(argv)
8
+ if argv.include?("--help") || argv.include?("-h")
9
+ puts "Usage: sight"
10
+ puts "Interactive git diff viewer (staged + unstaged)"
11
+ puts
12
+ puts "Keys: j/k/↑/↓ scroll, f/b page, d/u half-page, g/G top/bottom, n/p/→/← next/prev file, ? help, q quit"
13
+ return
14
+ end
15
+
16
+ if argv.include?("--version") || argv.include?("-v")
17
+ puts "sight #{VERSION}"
18
+ return
19
+ end
20
+
21
+ raw = Git.diff
22
+ if raw.empty?
23
+ warn "No diff output."
24
+ return
25
+ end
26
+
27
+ files = DiffParser.parse(raw)
28
+ App.new(files).run
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sight
4
+ DiffLine = Struct.new(:type, :content, :lineno, :old_lineno, keyword_init: true)
5
+ Hunk = Struct.new(:context, :lines, keyword_init: true)
6
+ DiffFile = Struct.new(:path, :hunks, keyword_init: true)
7
+
8
+ module DiffParser
9
+ module_function
10
+
11
+ def parse(raw)
12
+ files = []
13
+ current_file = nil
14
+ current_hunk = nil
15
+ new_lineno = nil
16
+ old_lineno = nil
17
+
18
+ raw.each_line(chomp: true) do |line|
19
+ if line.start_with?("diff --git ")
20
+ current_hunk = nil
21
+ path = line.split(" b/", 2).last
22
+ current_file = DiffFile.new(path: path, hunks: [])
23
+ files << current_file
24
+ elsif current_file.nil?
25
+ next
26
+ elsif line.start_with?("@@ ")
27
+ context, new_start, old_start = parse_hunk_header(line)
28
+ new_lineno = new_start
29
+ old_lineno = old_start
30
+ current_hunk = Hunk.new(context: context, lines: [])
31
+ current_file.hunks << current_hunk
32
+ elsif current_hunk
33
+ type = case line[0]
34
+ when "+" then :add
35
+ when "-" then :del
36
+ when "\\" then :meta
37
+ else :ctx
38
+ end
39
+ ln_old = (type == :add || type == :meta) ? nil : old_lineno
40
+ ln_new = (type == :del || type == :meta) ? nil : new_lineno
41
+ old_lineno += 1 if ln_old
42
+ new_lineno += 1 if ln_new
43
+ current_hunk.lines << DiffLine.new(type: type, content: line, lineno: ln_new, old_lineno: ln_old)
44
+ end
45
+ # skip other header lines (index, ---, +++)
46
+ end
47
+
48
+ files
49
+ end
50
+
51
+ def parse_hunk_header(line)
52
+ match = line.match(/@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)/)
53
+ return [nil, 1, 1] unless match
54
+ context = match[3].strip
55
+ old_start = match[1].to_i
56
+ new_start = match[2].to_i
57
+ [context.empty? ? nil : context, new_start, old_start]
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sight
4
+ DisplayLine = Struct.new(:type, :text, :lineno, keyword_init: true)
5
+ end
data/lib/sight/git.rb ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sight
4
+ module Git
5
+ module_function
6
+
7
+ def diff
8
+ output, success = run_cmd(["git", "diff", "--no-color", "HEAD"])
9
+ unless success
10
+ output, success = run_cmd(["git", "diff", "--no-color", "--cached"], err: [:child, :out])
11
+ raise Error, "git diff failed: #{output}" unless success
12
+ end
13
+ output
14
+ end
15
+
16
+ def run_cmd(cmd, err: IO::NULL)
17
+ output = IO.popen(cmd, err: err, &:read)
18
+ [output, $?.success?]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sight
4
+ VERSION = "0.1.0"
5
+ end
data/lib/sight.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sight/version"
4
+ require_relative "sight/display_line"
5
+ require_relative "sight/diff_parser"
6
+ require_relative "sight/git"
7
+ require_relative "sight/cli"
8
+ require_relative "sight/app"
9
+
10
+ module Sight
11
+ class Error < StandardError; end
12
+ end
data/sig/sight.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Sight
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sight
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ariel Rzezak
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: curses
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.4'
26
+ description: A TUI tool to browse git diffs interactively with colors, file navigation,
27
+ and scrolling.
28
+ email:
29
+ - arzezak@gmail.com
30
+ executables:
31
+ - sight
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - exe/sight
41
+ - lib/sight.rb
42
+ - lib/sight/app.rb
43
+ - lib/sight/cli.rb
44
+ - lib/sight/diff_parser.rb
45
+ - lib/sight/display_line.rb
46
+ - lib/sight/git.rb
47
+ - lib/sight/version.rb
48
+ - sig/sight.rbs
49
+ homepage: https://github.com/arzezak/sight
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ allowed_push_host: https://rubygems.org
54
+ homepage_uri: https://github.com/arzezak/sight
55
+ source_code_uri: https://github.com/arzezak/sight
56
+ changelog_uri: https://github.com/arzezak/sight/blob/main/CHANGELOG.md
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.2.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 4.0.7
72
+ specification_version: 4
73
+ summary: Interactive git diff viewer for the terminal
74
+ test_files: []