Skip to content

Commit 35a083e

Browse files
committed
Use Ctrl+R to run commands on windows
F***ing windows
1 parent f91a391 commit 35a083e

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

repl/docs.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,35 @@ func (pg playground) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
133133
pg.fileSelected = true
134134
pg.editor.Focus()
135135
}
136+
case tea.KeyCtrlR:
137+
if strings.Contains(pg.editor.Value(), "jaza") {
138+
pg.output.SetContent(styles.HelpStyle.Italic(false).Render("Samahani, huwezi kutumia `jaza()` kwa sasa."))
139+
} else {
140+
// this is just for the output will find a better solution
141+
code := strings.ReplaceAll(pg.editor.Value(), "andika", "_andika")
142+
pg.code = code
143+
env := object.NewEnvironment()
144+
l := lexer.New(pg.code)
145+
p := parser.New(l)
146+
program := p.ParseProgram()
147+
if len(p.Errors()) != 0 {
148+
pg.output.Style = styles.ErrorStyle.PaddingLeft(3)
149+
pg.output.SetContent(strings.Join(p.Errors(), "\n"))
150+
} else {
151+
evaluated := evaluator.Eval(program, env)
152+
if evaluated != nil {
153+
if evaluated.Type() != object.NULL_OBJ {
154+
pg.output.Style = styles.ReplStyle.PaddingLeft(3)
155+
content := evaluated.Inspect()
156+
l := strings.Split(content, "\n")
157+
if len(l) > 15 {
158+
content = strings.Join(l[len(l)-16:], "\n")
159+
}
160+
pg.output.SetContent(content)
161+
}
162+
}
163+
}
164+
}
136165
case tea.KeyEsc:
137166
if pg.fileSelected {
138167
pg.fileSelected = false
@@ -243,10 +272,10 @@ func (pg playground) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
243272
pg.windowHeight = msg.Height
244273

245274
if pg.language == "en" {
246-
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run")
275+
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run (CTRL + R)")
247276
} else {
248277

249-
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run")
278+
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run (CTRL + R)")
250279
}
251280
pg.ready = true
252281

@@ -274,9 +303,9 @@ func (pg playground) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
274303

275304
pg.docs.SetContent(str + "\n\n\n\n\n\n")
276305
if pg.language == "en" {
277-
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run")
306+
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run (CTRL + R)")
278307
} else {
279-
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run")
308+
pg.mybutton = activeButtonStyle.Width(msg.Width / 2).Height(1).Align(lipgloss.Center).Render("Run (CTRL + R)")
280309
}
281310
pg.toc.SetSize(msg.Width, msg.Height-8)
282311
pg.windowWidth = msg.Width

0 commit comments

Comments
 (0)