Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
92dc2eb
selection, and copy to clipboard
shimondoodkin Dec 7, 2023
da8119f
selection, and copy to clipboard
shimondoodkin Dec 7, 2023
af811c8
Merge branch 'mouse-wheel'
shimondoodkin Dec 7, 2023
4cc6e92
add copy all
shimondoodkin Dec 7, 2023
6198615
Merge branch 'select-and-copy'
shimondoodkin Dec 7, 2023
1aa1fb7
rstrip when copy
shimondoodkin Dec 7, 2023
2f3b3df
Merge branch 'select-and-copy' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
5972e7a
Merge branch 'fix-resize-before-running' of github.com:shimondoodkin/…
shimondoodkin Dec 7, 2023
0bcaa9b
tabs example
shimondoodkin Dec 7, 2023
cbb6f6c
Merge branch 'add-example-tabs' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
a1e1c55
allow change selection bg color
shimondoodkin Dec 7, 2023
1d13528
Merge branch 'select-and-copy' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
f6bb467
add screenshot example2
shimondoodkin Dec 7, 2023
9d437ed
add linux for the example2
shimondoodkin Dec 7, 2023
24d268b
Merge branch 'add-example-tabs' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
28d9bec
add parent for the widget in example2
shimondoodkin Dec 7, 2023
c12408d
Merge branch 'add-example-tabs' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
b6fb145
example 2 cmd caption
shimondoodkin Dec 7, 2023
2b7b6f2
Merge branch 'add-example-tabs' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
a2e5ff6
optimize selection
shimondoodkin Dec 7, 2023
1df156a
Merge branch 'select-and-copy'
shimondoodkin Dec 7, 2023
528b7ca
fix line selection
shimondoodkin Dec 7, 2023
cdb83e0
error when stream closed ubruptly
shimondoodkin Dec 7, 2023
a03ae8c
Merge branch 'select-and-copy' of github.com:shimondoodkin/termqt
shimondoodkin Dec 7, 2023
8800568
paste menu
shimondoodkin Dec 7, 2023
06e54dd
add shortcut keys
shimondoodkin Dec 7, 2023
4c90020
Merge branch 'shortcut-keys'
shimondoodkin Dec 7, 2023
b1dbebe
Merge branch 'master' into my-recent-changes
shimondoodkin Dec 9, 2023
c49909f
Delete example2.py
shimondoodkin Dec 9, 2023
3512a9a
Delete screenshots/example2.png
shimondoodkin Dec 9, 2023
f65d2fb
Update README.md
shimondoodkin Dec 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion termqt/colors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from Qt.QtGui import QColor
from PyQt5.QtGui import QColor

# This file stores all xterm-256 colors.
# See https://jonasjacek.github.io/colors/
Expand Down
100 changes: 98 additions & 2 deletions termqt/terminal_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from functools import partial
from collections import deque

from Qt.QtGui import QColor
from Qt.QtCore import Qt, QMutex
from PyQt5.QtGui import QColor
from PyQt5.QtCore import Qt, QMutex

from .colors import colors8, colors16, colors256

Expand Down Expand Up @@ -637,6 +637,10 @@ def __init__(self,
self._alt_buffer_display_offset = None
self._alt_cursor_position = Position(0, 0)

# selection
self._selection_start = None
self._selection_end = None

# scroll bar
self._postpone_scroll_update = False
self._scroll_update_pending = False
Expand All @@ -657,6 +661,98 @@ def __init__(self,

self.create_buffer(row_len, col_len)

# Add methods to manage selection state

def set_selection_start(self, start_position):
self._selection_start = start_position
self._selection_end = start_position

def set_selection_end(self, end_position):
self._selection_end = end_position

def set_selection_finish(self, end_position):
self.set_selection_end(end_position)

start_col, start_row = self._selection_start
end_col, end_row = self._selection_end
if (start_row, start_col) == (end_row, end_col):
self._selection_start = self._selection_end = None

def reset_selection(self):
self._selection_start = None
self._selection_end = None

def get_selection(self):
# Ensure the selection is ordered correctly
if self._selection_start and self._selection_end:
start = min(self._selection_start, self._selection_end)
end = max(self._selection_start, self._selection_end)
return start, end
return None, None

def _get_selected_text(self):
start, end = self.get_selection()
if start and end:
selected_text = ""
for row in range(start.y, end.y + 1):
if 0 <= row < len(self._buffer):
line = self._buffer[row]
line_text = ""
for col in range(len(line)):
if start.y == end.y:
if start.x <= col <= end.x:
line_text += line[col].char if line[col] else ' '
elif row == start.y and col >= start.x:
line_text += line[col].char if line[col] else ' '
elif row == end.y and col <= end.x:
line_text += line[col].char if line[col] else ' '
elif start.y < row < end.y:
line_text += line[col].char if line[col] else ' '
selected_text += line_text + '\n'
return selected_text.strip('\n')
return ""

def _get_selected_text_rstrip(self):
start, end = self.get_selection()
if start and end:
selected_text = ""
for row in range(start.y, end.y + 1):
if 0 <= row < len(self._buffer):
line = self._buffer[row]
line_text = ""
for col in range(len(line)):
if start.y == end.y:
if start.x <= col <= end.x:
line_text += line[col].char if line[col] else ' '
elif row == start.y and col >= start.x:
line_text += line[col].char if line[col] else ' '
elif row == end.y and col <= end.x:
line_text += line[col].char if line[col] else ' '
elif start.y < row < end.y:
line_text += line[col].char if line[col] else ' '
selected_text += line_text.rstrip() + '\n'
return selected_text.strip('\n')
return ""

def _get_all_text(self):
all_text = ""
for row in self._buffer:
line_text = ''.join(c.char if c else ' ' for c in row)
all_text += line_text + '\n'
return all_text.strip('\n')

def _get_all_text_rstrip(self):
all_text = []
for row in self._buffer:
line_text = ''.join(c.char if c else ' ' for c in row).rstrip()
all_text.append(line_text)

# Remove empty lines at the end of the buffer
while all_text and not all_text[-1]:
all_text.pop()

return '\n'.join(all_text)

def _register_escape_callbacks(self):
ep = self.escape_processor
ep.erase_display_cb = self.erase_display
Expand Down
2 changes: 2 additions & 0 deletions termqt/terminal_io_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def _read_loop(self):
self.stdout_callback(bytes(buf, 'utf-8'))
else:
self.stdout_callback(buf)
except EOFError:
pass
finally:
self.logger.info("Spawned process has been killed")
if self.running:
Expand Down
Loading