#!/bin/bash . shy.sh 2sf() { local empty="$1" local index="$2" local pattern="$3" 2va l $index "[(m.start(),m.end()) for m in finditer(r'$pattern', data)]" 2fr - start,end $index 3fc s this_text_box.tag_add "\"$index\",f\"1.0+{start}c\",f\"1.0+{end}c\"" } BG='"#202124"' PANE_PROP='self,orient="horizontal",relief="flat",bg="#AAA",sashwidth=4' PANE2_PROP='self,orient="vertical",relief="flat",bg="#AAA",sashwidth=4' PANE_PACK='expand=1,fill="both",padx=0,pady=0' TEXT_PROP='self,wrap="word",undo=True,highlightbackground="#202124",bg="#202124",fg="#CCC",font=("Iosevka",16),relief="flat",padx=10,pady=10,blockcursor=True,insertbackground="red",highlightcolor="#444",cursor="heart",selectbackground="#DDD",selectforeground="teal"' TEXT_PACK='expand=1,fill="both",padx=2,pady=2' STATS_PROP='self,textvariable=self.words_var,relief="flat",bg="#202124",fg="#BBB",font=("Iosevka",16)' STATS_PACK='expand=0,fill="x",padx=0,pady=2' 0bang 0fm tkinter Tk,Frame,Text,PanedWindow,Label,StringVar 0in subprocess 0fm re finditer 0dc ShyEd Tk 1df s __init__ 2fc l "super().__init__" 2fc s configure bg=$BG 2vf s main_pane PanedWindow $PANE2_PROP 2fc s main_pane.pack $PANE_PACK 2fc s main_pane.bind_all '"", self.add_text_frame' 2fc s add_text_frame 1de s add_text_frame 2vf s this_text MyTextFrame self 2fc ss main_pane.add this_text 0dc MyTextFrame Frame 1df s __init__ parent 2fc l "super().__init__" parent 2va s master parent 2fc s configure bg=$BG 2vf s this_pane PanedWindow $PANE_PROP 2fc s this_pane.pack $PANE_PACK 2fc s this_pane.bind_all '"", self.add_text_box' 2fc s add_text_box 1de s add_text_box 2vf s this_text MyTextBox self 2fc ss this_pane.add this_text 0dc MyTextBox Frame 1df s __init__ parent 2fc l "super().__init__" parent 2va s master parent 2fc s configure bg=$BG 2vf s this_text_box Text $TEXT_PROP 2fc s this_text_box.pack $TEXT_PACK 2vf s words_var StringVar 2fc s words_var.set '"0 | 1"' 2vf s stats_label Label $STATS_PROP 2fc s stats_label.pack $STATS_PACK 2fc s this_text_box.focus 2fc s tagConf 2fc s this_text_box.bind '"", self.openFile' 2fc s this_text_box.bind '"", self.saveFile' 2fc s this_text_box.bind '"", self.runCmd' 2fc s this_text_box.bind '"", self.doSyntax' 2fc s this_text_box.bind '"", self.changeFontSize' 2fc s this_text_box.bind '"", self.countWords' 2fc s this_text_box.bind '"", self.changeBg' 2fc s this_text_box.bind '"", self.changeFg' 1de s changeFg 2vf ls fg_color this_text_box.get '"insert linestart","insert lineend"' 2fc s this_text_box.delete '"insert linestart","insert lineend"' 2fc s this_text_box.configure 'fg=fg_color' 1de s changeBg 2vf ls bg_color this_text_box.get '"insert linestart","insert lineend"' 2fc s this_text_box.delete '"insert linestart","insert lineend"' 2fc s this_text_box.configure 'bg=bg_color' 1de s changeFontSize 2vf ls font_size this_text_box.get '"insert linestart","insert lineend"' 2fc s this_text_box.delete '"insert linestart","insert lineend"' 2fc s this_text_box.configure 'font=("Iosevka", int(font_size))' 1de s openFile 2vf ss line this_text_box.get '"insert linestart","insert lineend"' 2fc s this_text_box.delete '"insert linestart","insert lineend"' 2wi s open 'line,"r"' file 3vf l data file.read 2fc s this_text_box.insert '"1.0",data' 2fc s doSyntax 2fc s countWords 1de s saveFile 2vf ls data this_text_box.get '"1.0","end-1c"' 2wi s open 'line,"w"' file 3fc l file.write data 2fr fs tag this_text_box.tag_names 3fc s this_text_box.tag_remove 'tag,"1.0","end"' 2fc s doSyntax 1de s runCmd 2vf ls cmd this_text_box.get '"insert linestart","insert lineend"' 2try 3vf l output subprocess.run 'f"source shy.sh ; {cmd}",shell=True,executable="/bin/bash",stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True' 3if - output.returncode '== 0' 4fc s this_text_box.insert '"end",f"\n{output.stdout}\n"' 3el 4fc s this_text_box.insert '"end",f"\n{output.stderr}\n"' 2exc 3fc s this_text_box.insert '"end",f"\n{str(e)}\n"' 1de s tagConf 2va l tags_dict '{ "arg": ("#333", "#AAA"), "args": ("#444", "#AAA"), "c0": ("#202124", "teal"), "c1": ("#202124", "red"), "c2": ("#202124", "yellow"), "c3": ("#202124", "lime"), "c4": ("#202124", "blue"), "c5": ("#202124", "orange"), "c6": ("#202124", "purple"), "c7": ("#202124", "white"), "c8": ("#202124", "gray"), "c9": ("#202124", "cyan"),}' 2fr f key,value tags_dict.items 3fc s this_text_box.tag_configure 'key,background=value[0],foreground=value[1]' 1de s doSyntax 2vf ls data this_text_box.get '"1.0","end-1c"' 2sf - args '\"(.*?)\"' 2sf - arg "\'(.*?)\'" 2vf l all_lines data.splitlines 2fr f line_num,line enumerate 'all_lines,start=1' 3vf l words line.split 3if - 'not words' 3cnt 3va l first_word words[0] 3fr f index,char enumerate first_word 4if f char.isdigit 5va l tag_name 'f"c{char}"' 5fc s this_text_box.tag_add 'tag_name,f"{line_num}.{index}",f"{line_num}.{index + 1}"' 1de s countWords 2vf ls data this_text_box.get '"1.0","end"' 2vf l words_counted data.split 2vf l lines_counted data.split '"\n"' 2fc s words_var.set 'f"{len(words_counted)} | {len(lines_counted)-1}"' 0mn ShyEd Shy-Edit