Skip to content

Commit

Permalink
syntax highlight for diff view
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 25, 2024
1 parent 7752a0e commit bc308a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mutmut/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,9 @@ def browse():
from textual.containers import Container
from textual.widgets import Footer
from textual.widgets import DataTable
from textual.widgets import TextArea
from textual.widgets import Static
from textual.widget import Widget
from rich.syntax import Syntax

class ResultBrowser(App):
loading_id = None
Expand All @@ -1488,7 +1490,8 @@ def compose(self):
with Container(classes='container'):
yield DataTable(id='files')
yield DataTable(id='mutants')
yield TextArea(id='diff_view')
with Widget(id="diff_view_widget"):
yield Static(id='diff_view')
yield Footer()

def on_mount(self):
Expand Down Expand Up @@ -1547,19 +1550,19 @@ def on_data_table_row_highlighted(self, event):
assert event.data_table.id == 'mutants'
diff_view = self.query_one('#diff_view')
if event.row_key.value is None:
diff_view.text = ''
diff_view.update('')
else:
diff_view.text = '<loading...>'
diff_view.update('<loading...>')
self.loading_id = event.row_key.value

def load_thread():
read_config()
try:
d = get_diff_for_mutant(event.row_key.value)
if event.row_key.value == self.loading_id:
diff_view.text = d
diff_view.update(Syntax(d, "diff"))
except Exception as e:
diff_view.text = f'<{type(e)} {e}>'
diff_view.update(f"<{type(e)} {e}>")

t = Thread(target=load_thread)
t.start()
Expand Down
9 changes: 9 additions & 0 deletions mutmut/result_browser_layout.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,12 @@ DataTable:focus .datatable--cursor {
color: black;
background: orange;
}

#diff_view_widget{
height: 50%;
border: solid;
overflow-y: scroll;
}

#diff_view{
}

0 comments on commit bc308a1

Please sign in to comment.