Commit ffaee2d4 authored by Roman Alifanov's avatar Roman Alifanov

Added the ability to answer a question from the terminal (such as [Y/n])

parent e41d7d27
......@@ -49,6 +49,8 @@ class CommandRunner:
cleaned_output = remove_ansi_escape_sequences(output)
append_log(cleaned_output)
self.dialog.question_revealer.set_reveal_child(False)
# Check for the pattern in the output (letters in any order)
pattern = rf'\[([{yes_no_chars}])/([{yes_no_chars}])\]'
......@@ -57,18 +59,27 @@ class CommandRunner:
first_option, second_option = match.groups()
print(f"First option: {first_option}, Second option: {second_option}")
self.dialog.question_label.set_label(cleaned_output)
for css in ["suggested-action", "destructive-action"]:
self.dialog.question_button_1.remove_css_class(css)
self.dialog.question_button_2.remove_css_class(css)
# Check which one is destructive (nNнН)
destructive_option = None
self.dialog.question_button_1.connect("activated", lambda _: os.write(fd, f"{first_option}\n".encode('utf-8')))
self.dialog.question_button_2.connect("activated", lambda _: os.write(fd, f"{second_option}\n".encode('utf-8')))
self.dialog.question_button_1.set_title(first_option)
self.dialog.question_button_2.set_title(second_option)
if first_option in 'nNнН':
destructive_option = first_option
self.dialog.question_button_1.add_css_class("destructive-action")
self.dialog.question_button_2.add_css_class("suggested-action")
elif second_option in 'nNнН':
destructive_option = second_option
if destructive_option:
print(f"Destructive option '{destructive_option}' detected!")
self.dialog.question_button_2.add_css_class("destructive-action")
self.dialog.question_button_1.add_css_class("suggested-action")
#os.write(fd, b'y\n')
self.dialog.question_revealer.set_reveal_child(True)
else:
break
except OSError as e:
......@@ -82,7 +93,8 @@ class CommandRunner:
env['TERM'] = 'xterm'
process = subprocess.Popen(command, shell=True,
stdout=slave_fd, stderr=slave_fd, text=True, env=env)
stdout=slave_fd, stderr=slave_fd, stdin=slave_fd,
text=True, env=env)
os.close(slave_fd)
# Use selectors to manage I/O
......
......@@ -14,7 +14,16 @@
(1,2,"AdwClamp",None,1,None,None,None,0,None,None),
(1,3,"GtkBox",None,2,None,None,None,0,None,None),
(1,4,"GtkScrolledWindow",None,3,None,None,None,0,None,None),
(1,5,"GtkTextView","logdialog_textview",4,None,None,None,0,"",None)
(1,5,"GtkTextView","logdialog_textview",4,None,None,None,0,None,None),
(1,6,"GtkRevealer","question_revealer",3,None,None,None,1,None,None),
(1,7,"AdwClamp",None,6,None,None,None,0,None,None),
(1,8,"GtkBox",None,7,None,None,None,0,None,None),
(1,9,"GtkLabel","question_label",8,None,None,None,0,None,None),
(1,10,"GtkBox",None,8,None,None,None,1,None,None),
(1,11,"GtkListBox",None,10,None,None,None,0,None,None),
(1,12,"AdwButtonRow","question_button_1",11,None,None,None,0,None,None),
(1,13,"GtkListBox",None,10,None,None,None,1,None,None),
(1,14,"AdwButtonRow","question_button_2",13,None,None,None,0,None,None)
</object>
<object_property>
(1,1,"AdwDialog","can-close","false",0,None,None,None,None,None,None,None,None),
......@@ -27,14 +36,48 @@
(1,2,"GtkWidget","margin-top","12",0,None,None,None,None,None,None,None,None),
(1,3,"GtkBox","spacing","12",0,None,None,None,None,None,None,None,None),
(1,3,"GtkOrientable","orientation","vertical",0,None,None,None,None,None,None,None,None),
(1,4,"GtkWidget","height-request","259",0,None,None,None,None,None,None,None,None),
(1,4,"GtkScrolledWindow","hscrollbar-policy","never",0,None,None,None,None,None,None,None,None),
(1,4,"GtkWidget","height-request","300",0,None,None,None,None,None,None,None,None),
(1,4,"GtkWidget","vexpand","true",0,None,None,None,None,None,None,None,None),
(1,4,"GtkWidget","width-request","304",0,None,None,None,None,None,None,None,None),
(1,4,"GtkWidget","width-request","198",0,None,None,None,None,None,None,None,None),
(1,5,"GtkTextView","cursor-visible","false",0,None,None,None,None,None,None,None,None),
(1,5,"GtkTextView","editable","false",0,None,None,None,None,None,None,None,None),
(1,5,"GtkTextView","input-purpose","terminal",0,None,None,None,None,None,None,None,None),
(1,5,"GtkTextView","monospace","True",0,None,None,None,None,None,None,None,None),
(1,5,"GtkWidget","can-focus","False",None,None,None,None,None,None,None,None,None),
(1,5,"GtkWidget","can-target","False",None,None,None,None,None,None,None,None,None),
(1,5,"GtkWidget","focus-on-click","False",None,None,None,None,None,None,None,None,None)
(1,5,"GtkTextView","wrap-mode","word-char",0,None,None,None,None,None,None,None,None),
(1,5,"GtkWidget","can-focus","False",0,None,None,None,None,None,None,None,None),
(1,5,"GtkWidget","can-target","False",0,None,None,None,None,None,None,None,None),
(1,5,"GtkWidget","focus-on-click","False",0,None,None,None,None,None,None,None,None),
(1,6,"GtkRevealer","child",None,0,None,None,None,7,None,None,None,None),
(1,7,"GtkWidget","margin-bottom","12",0,None,None,None,None,None,None,None,None),
(1,7,"GtkWidget","margin-end","12",0,None,None,None,None,None,None,None,None),
(1,7,"GtkWidget","margin-start","12",0,None,None,None,None,None,None,None,None),
(1,7,"GtkWidget","margin-top","12",0,None,None,None,None,None,None,None,None),
(1,8,"GtkOrientable","orientation","vertical",0,None,None,None,None,None,None,None,None),
(1,9,"GtkLabel","justify","center",0,None,None,None,None,None,None,None,None),
(1,9,"GtkLabel","label","question_label",0,None,None,None,None,None,None,None,None),
(1,9,"GtkLabel","wrap","True",0,None,None,None,None,None,None,None,None),
(1,9,"GtkLabel","wrap-mode","word-char",0,None,None,None,None,None,None,None,None),
(1,9,"GtkWidget","halign","center",0,None,None,None,None,None,None,None,None),
(1,9,"GtkWidget","margin-bottom","12",0,None,None,None,None,None,None,None,None),
(1,9,"GtkWidget","valign","center",0,None,None,None,None,None,None,None,None),
(1,10,"GtkBox","spacing","12",0,None,None,None,None,None,None,None,None),
(1,11,"GtkWidget","hexpand","True",0,None,None,None,None,None,None,None,None),
(1,12,"AdwPreferencesRow","title","n",0,None,None,None,None,None,None,None,None),
(1,13,"GtkWidget","hexpand","True",0,None,None,None,None,None,None,None,None),
(1,14,"AdwPreferencesRow","title","Y",0,None,None,None,None,None,None,None,None)
</object_property>
<object_data>
(1,9,"GtkWidget",1,1,None,None,None,None,None,None),
(1,11,"GtkWidget",1,1,None,None,None,None,None,None),
(1,11,"GtkWidget",2,2,None,1,None,None,None,None),
(1,13,"GtkWidget",1,1,None,None,None,None,None,None),
(1,13,"GtkWidget",2,2,None,1,None,None,None,None),
(1,9,"GtkWidget",2,2,None,1,None,None,None,None)
</object_data>
<object_data_arg>
(1,11,"GtkWidget",2,2,"name","boxed-list"),
(1,13,"GtkWidget",2,2,"name","boxed-list"),
(1,9,"GtkWidget",2,2,"name","title-4")
</object_data_arg>
</cambalache-project>
......@@ -7,6 +7,11 @@ class LogDialog(Adw.Dialog):
__gtype_name__ = 'LogDialog'
logdialog_textview = Gtk.Template.Child()
question_revealer = Gtk.Template.Child()
question_label = Gtk.Template.Child()
question_button_1 = Gtk.Template.Child()
question_button_2 = Gtk.Template.Child()
def __init__(self, win, **kwargs):
super().__init__(**kwargs)
self.win = win
......
......@@ -22,9 +22,10 @@
<property name="spacing">12</property>
<child>
<object class="GtkScrolledWindow">
<property name="height-request">259</property>
<property name="height-request">300</property>
<property name="hscrollbar-policy">never</property>
<property name="vexpand">true</property>
<property name="width-request">304</property>
<property name="width-request">198</property>
<child>
<object class="GtkTextView" id="logdialog_textview">
<property name="can-focus">False</property>
......@@ -32,12 +33,75 @@
<property name="cursor-visible">false</property>
<property name="editable">false</property>
<property name="focus-on-click">False</property>
<property name="input-purpose">terminal</property>
<property name="monospace">True</property>
<!-- Custom object fragments -->
<property name="wrap-mode">word-char</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkRevealer" id="question_revealer">
<property name="child">
<object class="AdwClamp">
<property name="margin-bottom">12</property>
<property name="margin-end">12</property>
<property name="margin-start">12</property>
<property name="margin-top">12</property>
<child>
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="question_label">
<property name="halign">center</property>
<property name="justify">center</property>
<property name="label">question_label</property>
<property name="margin-bottom">12</property>
<property name="valign">center</property>
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<style>
<class name="title-4"/>
</style>
</object>
</child>
<child>
<object class="GtkBox">
<property name="spacing">12</property>
<child>
<object class="GtkListBox">
<property name="hexpand">True</property>
<child>
<object class="AdwButtonRow" id="question_button_1">
<property name="title">n</property>
</object>
</child>
<style>
<class name="boxed-list"/>
</style>
</object>
</child>
<child>
<object class="GtkListBox">
<property name="hexpand">True</property>
<child>
<object class="AdwButtonRow" id="question_button_2">
<property name="title">Y</property>
</object>
</child>
<style>
<class name="boxed-list"/>
</style>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment