Il suffit d'entrer une commande et le shell l'exécute. Pour l'instant le choix des commandes est encore trés restreint, mais je compte en ajouter par la suite.
Les commandes de bases sont :
- cmd : ouvre l'invite de commandes Windows (cmd.exe) dans le terminal
- help : Affiche l'aide
- clear : Devrait effacer la console avec ClearConsole(), mais ne fait rien
- date : Affiche la date
- system : Librairie System
- name : Donne le nom de l'ordinateur
- serial : Donne le numéro de série de l'ordinateur
- username : Renvoie le nom de l'utilisateur connecté
- cpu : Renvoie le modéle du CPU installé
- help : Aide de la lib System
- dir : Librairie Directory
- home : Affiche le répertoire de l'utilisateur
- current : Affiche le répertoire courant (équivalent à pwd sous Linux)
- temporary : Affiche le rép. temporaire
- set : Change le répertoire de travail (celui du prompt). Il faut préciser entre " le nouveau répertoire : dir.set "nouveau répertoire"
- help : Affiche l'aide de la lib direrctory
J'ai ajouté de l'aide sur les commandes en entrant 'help' ou le nom de la lib + '.help'.
Pour l'instant, il n'y a que deux librairies : system et dir (gestion des répertoires, création, suppression, répertoires courants, récursivité).
J'ajouterai par la suite d'autres librairies comme 'file' pour gérer et ouvrir des fichiers, 'date' pour gérer les heures, 'process' pour les processus (pid, liste des process, kill de process), et pourquoi pas 'web' pour ce qui est de l'internet (dl de fichiers, connections, ping...), voire d'autres encore...
A savoir que ce n'est pas un simple wrapper de fonctions pb, c'est plus pour moi un outil de remplacement à cmd que je trouve un peu chiant. Seules les bases étant posées pour l'instant, il n'y a presque rien a voir
Le code :
Code : Tout sélectionner
prompt$ = "SH_SHELL 1.0 :: "+GetCurrentDirectory()+">"
help$ = ~"Sherman Shell Terminal Help page\nThis is the help of the ShermanShell Terminal.\nUse one of the following commands on the terminal when the prompt is visible on the terminal.\nCommands are :\nexit : Exits the terminal.\nclear : Clears the terminal's screen.\ncmd : Run the Windows's cmd.exe terminal.\nhelp : Displays this page.\n"
help_System$ = ~"System Lib Help\nThis page refers to the help of the System Library Commands in the Sherman Shell Terminal.\nCommands : \nsystem.name\t: returns the name of the current computer.\nsystem.cpu\t: Returns the name of the current used CPU.\nsystem.username : returns the name of the user currently logged on.\nsystem.serial\t: Returns the serial number of this computer.\nsystem.help\t: Displays this page.\n"
help_Directory$= ~"Directory lib Help\nThis page refers to the help of the Directory (dir) library\ndir.home\t:Returns the home directory.\ndir.current\t:Returns the current working directory. Same as 'pwd'.\ndir.temporary\t:Returns the temporary directory.\ndir.set\t:Changes the working directory to the new one (must be typed with \" before and after).\ndir.help\t:Displays this page.\n"
OpenConsole("Sherman Shell Terminal (SHSHELL)")
ConsoleColor(0,7)
PrintN(" (c)ShermanSoftware - Sherman Command-line Terminal ")
ConsoleColor(7,0)
PrintN("Console initializated. Command-line is now enabled.")
Repeat
Print(prompt$)
re$ = Input()
command$ = StringField(re$,1," ")
param$= StringField(re$,2," ")
lib$ = StringField(command$,1,".")
Select lib$
Case "cmd"
ExternalProg = RunProgram("cmd.exe","-help","",#PB_Program_Hide | #PB_Program_Open | #PB_Program_Read | #PB_Program_UTF8)
If ExternalProg
While ProgramRunning(ExternalProg)
If AvailableProgramOutput(ExternalProg)
PrintN(ReadProgramString(ExternalProg))
EndIf
Wend
PrintN("Execution finished")
Else
PrintN("Unable to run cmd.exe.")
EndIf
Case "exit"
End
Case "clear"
ClearConsole()
Case "-help"
PrintN(help$)
Case "help"
PrintN(help$)
Case "-h"
PrintN(help$)
Case "date"
PrintN(FormatDate("%dd/%mm/%yyyy, %hh:%ii:%ss",Date()))
Case "system"
Select StringField(re$,2,".")
Case "name"
PrintN(ComputerName())
Case "serial"
PrintN(ComputerSerialNumber())
Case "username"
PrintN(UserName())
Case "cpu"
PrintN(CPUName())
Case "help"
PrintN(help_System$)
Default
PrintN("This is not a command of the 'system' interface. Please refer to the related help by typing 'system.help' to see the System commands.")
EndSelect
Case "pwd"
PrintN(GetCurrentDirectory())
Case "dir"
Select StringField(command$,2,".")
Case "temporary"
PrintN(GetTemporaryDirectory())
Case "current"
PrintN(GetCurrentDirectory())
Case "home"
PrintN(GetHomeDirectory())
Case "help"
PrintN(help_Directory$)
Case "set"
currentDir$ = StringField(param$,2,~"\"")
If SetCurrentDirectory(currentDir$)
PrintN("Working directory changed to '"+currentDir$+"'.")
prompt$ = "SH_SHELL 1.0 :: "+GetCurrentDirectory()+">"
Else
PrintN("Unable to change the working directory to '"+currentDir$+"'. Make sure you entered a real directory name.")
EndIf
Default
PrintN("This is not a command of the 'dir' (Directory) interface. To see the list of available commands, please type 'dir.help'.")
EndSelect
Default
PrintN("'"+re$ + "' is not a command currently available in this terminal. Enter -h or -help for more help about the Sherman Shell Terminal.")
EndSelect
ForEver
Le prompt de cmd ne se réaffiche pas tout seul aprés une fonction de cmd.
L'autocomplétion avec Tab ne marche pas non plus.