fortrangoingonforty/fortress / e13b7ce

Browse files

change approach to cursor selection to give consistent cross-platform experience

Authored by espadonne
SHA
e13b7ce059bf1cc0ef0ff0ae60321685d666fd1f
Parents
6f6093e
Tree
12697be

4 changed files

StatusFile+-
M app/main.f90 5 0
M src/git/git_ops.f90 6 5
M src/terminal/term_control.f90 6 2
M src/ui/display.f90 12 14
app/main.f90modified
@@ -55,6 +55,11 @@ program fortress
5555
     call detect_git_repo(current_dir, in_git_repo, repo_name, branch_name)
5656
     call setup_raw_mode()
5757
 
58
+    ! Initialize selection array to false
59
+    do i = 1, MAX_FILES
60
+        is_selected(i) = .false.
61
+    end do
62
+
5863
     ! Main loop
5964
     do while (running)
6065
         ! Get files
src/git/git_ops.f90modified
@@ -239,31 +239,32 @@ contains
239239
     subroutine write_git_indicators(staged, unstaged, untracked, has_incoming, highlighted)
240240
         logical, intent(in) :: staged, unstaged, untracked, has_incoming, highlighted
241241
 
242
-        ! Write indicators without RESET (caller handles that)
242
+        ! When highlighted (cursor), don't change colors - just write symbols
243
+        ! When not highlighted, use colors with immediate RESET
243244
         if (staged) then
244245
             if (highlighted) then
245
-                write(output_unit, '(a)', advance='no') GREEN // " ↑"
246
+                write(output_unit, '(a)', advance='no') " ↑"
246247
             else
247248
                 write(output_unit, '(a)', advance='no') GREEN // " ↑" // RESET
248249
             end if
249250
         end if
250251
         if (unstaged) then
251252
             if (highlighted) then
252
-                write(output_unit, '(a)', advance='no') RED // " ✗"
253
+                write(output_unit, '(a)', advance='no') " ✗"
253254
             else
254255
                 write(output_unit, '(a)', advance='no') RED // " ✗" // RESET
255256
             end if
256257
         end if
257258
         if (untracked) then
258259
             if (highlighted) then
259
-                write(output_unit, '(a)', advance='no') GREY // " ✗"
260
+                write(output_unit, '(a)', advance='no') " ✗"
260261
             else
261262
                 write(output_unit, '(a)', advance='no') GREY // " ✗" // RESET
262263
             end if
263264
         end if
264265
         if (has_incoming) then
265266
             if (highlighted) then
266
-                write(output_unit, '(a)', advance='no') YELLOW // " ↓"
267
+                write(output_unit, '(a)', advance='no') " ↓"
267268
             else
268269
                 write(output_unit, '(a)', advance='no') YELLOW // " ↓" // RESET
269270
             end if
src/terminal/term_control.f90modified
@@ -4,8 +4,8 @@ module terminal_control
44
     private
55
 
66
     public :: get_term_size, setup_raw_mode, restore_terminal, read_arrow_key, read_arrow_key_with_shift
7
-    public :: ESC, CLEAR, BOLD, DIM, REVERSE, RESET
8
-    public :: BLUE, GREEN, RED, GREY, WHITE, YELLOW
7
+    public :: ESC, CLEAR, BOLD, DIM, REVERSE, NOREVERSE, RESET, UNDERLINE
8
+    public :: BLUE, GREEN, RED, GREY, WHITE, YELLOW, BG_WHITE, BLACK
99
     public :: invalidate_term_cache
1010
 
1111
     ! ANSI escape codes
@@ -13,7 +13,9 @@ module terminal_control
1313
     character(len=*), parameter :: CLEAR = ESC // "[2J" // ESC // "[H"
1414
     character(len=*), parameter :: BOLD = ESC // "[1m"
1515
     character(len=*), parameter :: DIM = ESC // "[2m"
16
+    character(len=*), parameter :: UNDERLINE = ESC // "[4m"
1617
     character(len=*), parameter :: REVERSE = ESC // "[7m"
18
+    character(len=*), parameter :: NOREVERSE = ESC // "[27m"  ! Explicitly turn off reverse video
1719
     character(len=*), parameter :: RESET = ESC // "[0m"
1820
     character(len=*), parameter :: BLUE = ESC // "[34m"
1921
     character(len=*), parameter :: GREEN = ESC // "[32m"
@@ -21,6 +23,8 @@ module terminal_control
2123
     character(len=*), parameter :: GREY = ESC // "[90m"
2224
     character(len=*), parameter :: WHITE = ESC // "[37m"
2325
     character(len=*), parameter :: YELLOW = ESC // "[33m"
26
+    character(len=*), parameter :: BLACK = ESC // "[30m"
27
+    character(len=*), parameter :: BG_WHITE = ESC // "[47m"  ! White background
2428
 
2529
     ! Terminal size cache
2630
     integer, save :: cached_rows = 0
src/ui/display.f90modified
@@ -1,6 +1,7 @@
11
 module ui_display
22
     use iso_fortran_env, only: output_unit
3
-    use terminal_control
3
+    use terminal_control, only: DIM, BOLD, RESET, UNDERLINE, &
4
+                                BLUE, GREEN, RED, GREY, WHITE, YELLOW
45
     use git_ops, only: write_git_indicators
56
     use filesystem_ops, only: MAX_PATH, MAX_FILES
67
     implicit none
@@ -100,11 +101,15 @@ contains
100101
                 write(output_unit, '(a)', advance='no') repeat(" ", left_w)
101102
             end if
102103
 
104
+            ! RESET before separator to clear any state from parent pane
105
+            write(output_unit, '(a)', advance='no') RESET
106
+
103107
             ! Separator
104108
             write(output_unit, '(a)', advance='no') " │ "
105109
 
106110
             ! Current pane
107111
             if (current_idx >= 1 .and. current_idx <= current_count) then
112
+
108113
                 fname = current_files(current_idx)
109114
                 if (current_is_dir(current_idx) .and. fname /= "." .and. fname /= "..") then
110115
                     fname = trim(fname) // "/"
@@ -132,8 +137,8 @@ contains
132137
                     write(output_unit, '(a)', advance='no') RED // BOLD // trim(fname) // RESET
133138
                     write(output_unit, '(a)') ""
134139
                 else if (move_mode .and. current_idx == move_dest_selected) then
135
-                    ! Destination cursor - show with white background
136
-                    write(output_unit, '(a)', advance='no') REVERSE // WHITE // trim(fname)
140
+                    ! Destination cursor - show with bold+underline
141
+                    write(output_unit, '(a)', advance='no') BOLD // UNDERLINE // WHITE // trim(fname)
137142
                     if (in_git_repo) then
138143
                         call write_git_indicators(current_is_staged(current_idx), &
139144
                                                   current_is_unstaged(current_idx), &
@@ -142,15 +147,8 @@ contains
142147
                     end if
143148
                     write(output_unit, '(a)') RESET
144149
                 else if (current_idx == selected .and. .not. move_mode) then
145
-                    ! Normal selection cursor (not in move mode)
146
-                    ! If file is cut, show selected with red background instead of default color
147
-                    ! Only highlight for single-item cuts (multi-cuts shown in header)
148
-                    if (has_clipboard .and. clipboard_is_cut .and. clipboard_count == 1 .and. &
149
-                        trim(current_files(current_idx)) == trim(clipboard_source_name)) then
150
-                        write(output_unit, '(a)', advance='no') REVERSE // RED // trim(fname)
151
-                    else
152
-                        write(output_unit, '(a)', advance='no') REVERSE // trim(color_code) // trim(fname)
153
-                    end if
150
+                    ! Normal selection cursor (not in move mode) - use bold+underline with original color
151
+                    write(output_unit, '(a)', advance='no') BOLD // UNDERLINE // trim(color_code) // trim(fname)
154152
                     ! Add git indicators if in repo
155153
                     if (in_git_repo) then
156154
                         call write_git_indicators(current_is_staged(current_idx), &
@@ -160,8 +158,8 @@ contains
160158
                     end if
161159
                     write(output_unit, '(a)') RESET
162160
                 else if (is_selected(current_idx)) then
163
-                    ! Multi-selected item (not the cursor) - show with cyan background
164
-                    write(output_unit, '(a)', advance='no') REVERSE // trim(color_code) // trim(fname)
161
+                    ! Multi-selected item (not the cursor) - show with underline
162
+                    write(output_unit, '(a)', advance='no') UNDERLINE // trim(color_code) // trim(fname)
165163
                     ! Add git indicators if in repo
166164
                     if (in_git_repo) then
167165
                         call write_git_indicators(current_is_staged(current_idx), &