fortrangoingonforty/facsimile / 06c086c

Browse files

updates i think

Authored by espadonne
SHA
06c086ce7a6958bc1712d667c5bfe04c8d4badc8
Parents
247967b
Tree
0b0a666

3 changed files

StatusFile+-
M src/clipboard/clipboard_module.f90 2 2
M src/commands/command_handler_module.f90 6 0
M src/terminal/renderer_module.f90 52 8
src/clipboard/clipboard_module.f90modified
@@ -53,13 +53,13 @@ contains
5353
         if (ios == 0) then
5454
             ! Read the clipboard content
5555
             open(newunit=unit, file='/tmp/facsimile_clipboard.tmp', &
56
-                 status='old', action='read', iostat=ios)
56
+                 status='old', action='read', access='stream', iostat=ios)
5757
 
5858
             if (ios == 0) then
5959
                 ! Get file size
6060
                 inquire(unit=unit, size=file_size)
6161
                 if (file_size > 0 .and. file_size < 1000000) then
62
-                    read(unit, '(a)', iostat=ios) buffer(1:file_size)
62
+                    read(unit, iostat=ios) buffer(1:file_size)
6363
                     if (ios == 0) then
6464
                         allocate(character(len=file_size) :: text)
6565
                         text = buffer(1:file_size)
src/commands/command_handler_module.f90modified
@@ -797,12 +797,16 @@ contains
797797
             ! opt-meta-up: Doesn't work (terminals don't send Cmd)
798798
             ! ctrl-alt-up: Alternative binding that works
799799
             call add_cursor_above(editor, buffer)
800
+            call sync_editor_to_pane(editor)
801
+            call update_viewport(editor)
800802
 
801803
         case('opt-meta-down', 'ctrl-alt-down', 'alt-ctrl-down')
802804
             ! Add cursor on line below
803805
             ! opt-meta-down: Doesn't work (terminals don't send Cmd)
804806
             ! ctrl-alt-down: Alternative binding that works
805807
             call add_cursor_below(editor, buffer)
808
+            call sync_editor_to_pane(editor)
809
+            call update_viewport(editor)
806810
 
807811
         ! Search commands
808812
         case('ctrl-f')
@@ -830,6 +834,7 @@ contains
830834
                 else
831835
                     call insert_char(editor%cursors(editor%active_cursor), buffer, 'n')
832836
                 end if
837
+                call sync_editor_to_pane(editor)
833838
                 is_edit_action = .true.
834839
             end if
835840
 
@@ -846,6 +851,7 @@ contains
846851
                 else
847852
                     call insert_char(editor%cursors(editor%active_cursor), buffer, 'N')
848853
                 end if
854
+                call sync_editor_to_pane(editor)
849855
                 is_edit_action = .true.
850856
             end if
851857
 
src/terminal/renderer_module.f90modified
@@ -189,10 +189,10 @@ contains
189189
             if (allocated(editor%tabs(editor%active_tab_index)%panes)) then
190190
                 call render_cursor_for_panes(editor)
191191
             else
192
-                call render_cursor(editor)
192
+                call render_cursor(editor, buffer)
193193
             end if
194194
         else
195
-            call render_cursor(editor)
195
+            call render_cursor(editor, buffer)
196196
         end if
197197
     end subroutine render_screen
198198
 
@@ -442,12 +442,15 @@ contains
442442
         call terminal_write(char(27) // '[0m')  ! Reset attributes
443443
     end subroutine render_status_bar
444444
 
445
-    subroutine render_cursor(editor)
445
+    subroutine render_cursor(editor, buffer)
446446
         type(editor_state_t), intent(in) :: editor
447
+        type(buffer_t), intent(in) :: buffer
447448
         type(cursor_t) :: cursor
448449
         integer :: screen_row, screen_col
449450
         integer :: i
450451
         integer :: col_offset, row_offset, min_row
452
+        character(len=:), allocatable :: line
453
+        character :: cursor_char
451454
 
452455
         ! Calculate column offset for line numbers
453456
         if (show_line_numbers) then
@@ -479,9 +482,17 @@ contains
479482
                     ! Ensure cursor is within screen bounds and not in tab bar
480483
                     if (screen_row >= min_row .and. screen_row < editor%screen_rows .and. &
481484
                         screen_col >= 1 .and. screen_col <= editor%screen_cols) then
482
-                        ! Inactive cursor - draw with reverse video block
485
+                        ! Get the character at this cursor position
486
+                        line = buffer_get_line(buffer, cursor%line)
487
+                        if (cursor%column <= len(line)) then
488
+                            cursor_char = line(cursor%column:cursor%column)
489
+                        else
490
+                            cursor_char = ' '  ! End of line
491
+                        end if
492
+
493
+                        ! Inactive cursor - draw character with reverse video
483494
                         call terminal_move_cursor(screen_row, screen_col)
484
-                        call terminal_write(char(27) // '[7m ')  ! Inverse video space
495
+                        call terminal_write(char(27) // '[7m' // cursor_char)  ! Inverse video
485496
                         call terminal_write(char(27) // '[0m')   ! Reset
486497
                     end if
487498
                 end if
@@ -1069,11 +1080,13 @@ contains
10691080
         type(editor_state_t), intent(in) :: editor
10701081
         type(pane_t) :: pane
10711082
         type(cursor_t) :: cursor
1072
-        integer :: tab_idx, pane_idx
1083
+        integer :: tab_idx, pane_idx, i
10731084
         integer :: pane_col, pane_row, pane_width, pane_height
10741085
         integer :: screen_row, screen_col
10751086
         integer :: screen_width, screen_height
10761087
         integer :: col_offset
1088
+        character(len=:), allocatable :: line
1089
+        character :: cursor_char
10771090
 
10781091
         tab_idx = editor%active_tab_index
10791092
         if (tab_idx < 1 .or. tab_idx > size(editor%tabs)) return
@@ -1086,8 +1099,6 @@ contains
10861099
         if (.not. allocated(pane%cursors)) return
10871100
         if (pane%active_cursor < 1 .or. pane%active_cursor > size(pane%cursors)) return
10881101
 
1089
-        cursor = pane%cursors(pane%active_cursor)
1090
-
10911102
         ! Calculate column offset for line numbers
10921103
         if (show_line_numbers) then
10931104
             col_offset = LINE_NUMBER_WIDTH + 1  ! +1 for separator space
@@ -1107,6 +1118,39 @@ contains
11071118
         pane_row = 2 + int(pane%y_start * real(screen_height))
11081119
         pane_height = int((pane%y_end - pane%y_start) * real(screen_height))
11091120
 
1121
+        ! For multiple cursors, render all inactive ones first
1122
+        if (size(pane%cursors) > 1) then
1123
+            do i = 1, size(pane%cursors)
1124
+                if (i /= pane%active_cursor) then
1125
+                    cursor = pane%cursors(i)
1126
+
1127
+                    ! Calculate cursor position within the pane
1128
+                    screen_row = pane_row + (cursor%line - pane%viewport_line)
1129
+                    screen_col = pane_col + col_offset + (cursor%column - pane%viewport_column)
1130
+
1131
+                    ! Ensure cursor is within pane boundaries
1132
+                    if (screen_row >= pane_row .and. screen_row < pane_row + pane_height .and. &
1133
+                        screen_col >= pane_col + col_offset .and. screen_col < pane_col + pane_width) then
1134
+                        ! Get the character at this cursor position
1135
+                        line = buffer_get_line(editor%tabs(tab_idx)%buffer, cursor%line)
1136
+                        if (cursor%column <= len(line)) then
1137
+                            cursor_char = line(cursor%column:cursor%column)
1138
+                        else
1139
+                            cursor_char = ' '  ! End of line
1140
+                        end if
1141
+
1142
+                        ! Inactive cursor - draw character with reverse video
1143
+                        call terminal_move_cursor(screen_row, screen_col)
1144
+                        call terminal_write(char(27) // '[7m' // cursor_char)  ! Inverse video
1145
+                        call terminal_write(char(27) // '[0m')   ! Reset
1146
+                    end if
1147
+                end if
1148
+            end do
1149
+        end if
1150
+
1151
+        ! Now render the active cursor
1152
+        cursor = pane%cursors(pane%active_cursor)
1153
+
11101154
         ! Calculate cursor position within the pane, accounting for line numbers
11111155
         screen_row = pane_row + (cursor%line - pane%viewport_line)
11121156
         screen_col = pane_col + col_offset + (cursor%column - pane%viewport_column)