We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small Basic CMD simulator
#1
Finally,

After publishing my Bash simulator, I've tried to expand it's very basic code.

ID: ZVVD6.000
Link: https://smallbasic.com/program/?ZVVD6.000

Code:
TextWindow.Hide()
TextWindow.Title = "Windows Command Prompt"
year = Clock.Year
path = "C:\Windows\System32"
helpInfoTxt[1] = "== HELP =="
helpInfoTxt[2] = "dir <path> - Lists files from a path."
helpInfoTxt[3] = "echo <text> - Writes line to the prompt."
helpInfoTxt[4] = "cd <path> - Enters a path."
helpInfoTxt[5] = "help - Shows this text."
TextWindow.Show()
TextWindow.ForegroundColor = "White"
TextWindow.WriteLine("Copyright "+year+" sm4llprogrammer2008")
While ("True")
  TextWindow.ForegroundColor = "White"
  TextWindow.Write(path+">> ")
  TextWindow.ForegroundColor = "Gray"
  prompt = TextWindow.Read()
  EventHandler()
EndWhile

Sub EventHandler 'We'll return events based on input (variable: prompt)
  getting = LDText.Split(prompt, " ") 'Split text
    If getting[1] = "dir" Then 'Event handler for dir
      getpath = getting[2]
      If Text.GetIndexOf(getpath, "C:\") = 1 Then
        files = File.GetFiles(getpath) 'Get files
        For i = 1 To Array.GetItemCount(files) 'List all files from the directory input by the user
          TextWindow.WriteLine(files[i])
        EndFor
      Else 'If no path is typed or none
          TextWindow.WriteLine("Invalid path. Use a valid directory starting with C:\")
     EndIf
    ElseIf getting[1] = "cd" Then 'Event handler for cd
      getpath = getting[2]
      If Text.GetIndexOf(getpath, "C:\") = 1 Then
        path = getpath
      Else
        TextWindow.WriteLine("Invalid path. Use a valid directory starting with C:\")
      EndIf
    ElseIf getting[1] = "echo" Then
      returning = Text.GetSubText(prompt, Text.GetIndexOf(prompt, "echo") + 5, Text.GetLength(prompt) - Text.GetIndexOf(prompt, "echo") - 4)
      TextWindow.WriteLine(returning)
    ElseIf getting[1] = "help" Then
      For i = 1 To Array.GetItemCount(helpInfoTxt)
        TextWindow.WriteLine(helpInfoTxt[i])
      EndFor
    Else
      TextWindow.WriteLine("Unknown command. Type 'help' for info.")
    EndIf
EndSub

Feel free to expand!

Edit: requires LitDev Beta library!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)