github.com/jmigpin/editor@v1.6.0/core/internalcmds/misc.go (about) 1 package internalcmds 2 3 import ( 4 "fmt" 5 6 "github.com/jmigpin/editor/core" 7 "github.com/jmigpin/editor/ui" 8 "github.com/jmigpin/editor/util/ctxutil" 9 "github.com/jmigpin/editor/util/iout" 10 "github.com/jmigpin/editor/util/osutil" 11 ) 12 13 //---------- 14 15 func Version(args *core.InternalCmdArgs) error { 16 args.Ed.Messagef("version: %v", core.Version()) 17 return nil 18 } 19 20 //---------- 21 22 func Exit(args *core.InternalCmdArgs) error { 23 args.Ed.Close() 24 return nil 25 } 26 27 //---------- 28 29 func SaveSession(args *core.InternalCmdArgs) error { 30 core.SaveSession(args.Ed, args.Part) 31 return nil 32 } 33 func OpenSession(args *core.InternalCmdArgs) error { 34 core.OpenSession(args.Ed, args.Part) 35 return nil 36 } 37 func DeleteSession(args *core.InternalCmdArgs) error { 38 core.DeleteSession(args.Ed, args.Part) 39 return nil 40 } 41 func ListSessions(args *core.InternalCmdArgs) error { 42 core.ListSessions(args.Ed) 43 return nil 44 } 45 46 //---------- 47 48 func NewColumn(args *core.InternalCmdArgs) error { 49 args.Ed.NewColumn() 50 return nil 51 } 52 func CloseColumn(args *core.InternalCmdArgs) error { 53 args.ERow.Row.Col.Close() 54 return nil 55 } 56 57 //---------- 58 59 func CloseRow(args *core.InternalCmdArgs) error { 60 args.ERow.Row.Close() 61 return nil 62 } 63 func ReopenRow(args *core.InternalCmdArgs) error { 64 args.Ed.RowReopener.Reopen() 65 return nil 66 } 67 func MaximizeRow(args *core.InternalCmdArgs) error { 68 args.ERow.Row.Maximize() 69 return nil 70 } 71 72 //---------- 73 74 func Save(args *core.InternalCmdArgs) error { 75 return args.ERow.Info.SaveFile() 76 } 77 func SaveAllFiles(args *core.InternalCmdArgs) error { 78 var me iout.MultiError 79 for _, info := range args.Ed.ERowInfos() { 80 if info.IsFileButNotDir() { 81 me.Add(info.SaveFile()) 82 } 83 } 84 return me.Result() 85 } 86 87 //---------- 88 89 func Reload(args *core.InternalCmdArgs) error { 90 args.ERow.Reload() 91 return nil 92 } 93 func ReloadAllFiles(args *core.InternalCmdArgs) error { 94 var me iout.MultiError 95 for _, info := range args.Ed.ERowInfos() { 96 if info.IsFileButNotDir() { 97 me.Add(info.ReloadFile()) 98 } 99 } 100 return me.Result() 101 } 102 func ReloadAll(args *core.InternalCmdArgs) error { 103 // reload all dirs erows 104 for _, info := range args.Ed.ERowInfos() { 105 if info.IsDir() { 106 for _, erow := range info.ERows { 107 erow.Reload() // TODO: handle error here 108 } 109 } 110 } 111 112 return ReloadAllFiles(args) 113 } 114 115 //---------- 116 117 func Stop(args *core.InternalCmdArgs) error { 118 args.ERow.Exec.Stop() 119 return nil 120 } 121 122 //---------- 123 124 func Clear(args *core.InternalCmdArgs) error { 125 args.ERow.Row.TextArea.SetStrClearHistory("") 126 return nil 127 } 128 129 //---------- 130 131 func OpenFilemanager(args *core.InternalCmdArgs) error { 132 erow := args.ERow 133 134 if erow.Info.IsSpecial() { 135 return fmt.Errorf("can't run on special row") 136 } 137 138 return osutil.OpenFilemanager(erow.Info.Dir()) 139 } 140 141 func OpenTerminal(args *core.InternalCmdArgs) error { 142 erow := args.ERow 143 144 if erow.Info.IsSpecial() { 145 return fmt.Errorf("can't run on special row") 146 } 147 148 return osutil.OpenTerminal(erow.Info.Dir()) 149 } 150 151 //---------- 152 153 func GoDebug(args *core.InternalCmdArgs) error { 154 args2 := args.Part.ArgsUnquoted() 155 return args.Ed.GoDebug.RunAsync(args.Ctx, args.ERow, args2) 156 } 157 158 func GoDebugFind(args *core.InternalCmdArgs) error { 159 a := args.Part.ArgsUnquoted() 160 if len(a) < 2 { 161 return fmt.Errorf("missing string to find") 162 } 163 s := "" 164 if len(a) == 2 { 165 s = a[1] // single arg, unquoted if quoted 166 } else { 167 s = args.Part.FromArgString(1) // verbatim 168 } 169 170 return args.Ed.GoDebug.AnnotationFind(s) 171 } 172 173 //---------- 174 175 func ColorTheme(args *core.InternalCmdArgs) error { 176 ui.ColorThemeCycler.Cycle(args.Ed.UI.Root) 177 args.Ed.UI.Root.MarkNeedsLayoutAndPaint() 178 return nil 179 } 180 func FontTheme(args *core.InternalCmdArgs) error { 181 ui.FontThemeCycler.Cycle(args.Ed.UI.Root) 182 args.Ed.UI.Root.MarkNeedsLayoutAndPaint() 183 return nil 184 } 185 186 //---------- 187 188 func FontRunes(args *core.InternalCmdArgs) error { 189 var u string 190 for i := 0; i < 15000; { 191 start := i 192 var w string 193 for j := 0; j < 25; j++ { 194 w += string(rune(i)) 195 i++ 196 } 197 u += fmt.Sprintf("%d: %s\n", start, w) 198 } 199 args.Ed.Messagef("%s", u) 200 return nil 201 } 202 203 //---------- 204 205 func LSProtoCloseAll(args *core.InternalCmdArgs) error { 206 return args.Ed.LSProtoMan.Close() 207 } 208 func CtxutilCallsState(args *core.InternalCmdArgs) error { 209 s := ctxutil.CallsState() 210 args.Ed.Messagef("%s", s) 211 return nil 212 }