This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Dave-ee Jones's profile picture

[adv] Shell-creating

Started by Dave-ee Jones, 16 October 2013 - 01:34 AM
Dave-ee Jones #1
Posted 16 October 2013 - 03:34 AM
Ok, now, I have seen many custom shells (copies of CraftOS) and I want to make one for a new program I am making, a program with it's own shell. (This program is NOT an OS, as I have already made 2, but one isn't published, even though it is awesome.)

I am wondering if there are any tutorials on how to get started with this? I haven't seen any, and none came up anywhere. If not, can someone whip up one? I am sure many people would love to create their own shell.

Thanks!
TheOddByte #2
Posted 16 October 2013 - 01:41 PM
Well I'm not sure, But you could possibly override the original shell functions and make your own in your own way… I have never gotten the idea of creating a custom shell, But it might be useful.. :)/>
H4X0RZ #3
Posted 16 October 2013 - 04:42 PM
Something like this?
Code

local running = true
lical hist = {}
local commandChar = "/" 
local bg, txt, er
if term.IsColor and term.isColor() then
  bg, txt, er = colors.gray, colors.white, colors.red
else
  bg, txt, er = colors.black, colors.white, colors.white
end
local function prepare(str)
  local cont = {}
  for word in string.gmatch(str,"[ ^ \t ]+")
  return cont
end
local function err(str)
  term.setTextColor(er)
  print(str)
  term.setTextColor(txt)
end
local commands = {
  ["exit"] = function() running = false end;
}

--# Main loop
while running do
  local inp = read(nil,hist)
  if inp:sub(1,1) == "/" and commands[inp:sub(2,#inp)] then
    commands[inp:sub(2,#inp)]()
  else
    err("command unknown")
  end
  local prep = prepare(inp)

  if fs.exists(inp[1]) then
    shell.run(inp)
  else
    err("file not found")
  end
  table.insert(hist,inp)
end
Should work but i don't know if the "regex" is correct.
Dave-ee Jones #4
Posted 17 October 2013 - 03:05 AM
Something like this?
Code

local running = true
lical hist = {}
local commandChar = "/"
local bg, txt, er
if term.IsColor and term.isColor() then
  bg, txt, er = colors.gray, colors.white, colors.red
else
  bg, txt, er = colors.black, colors.white, colors.white
end
local function prepare(str)
  local cont = {}
  for word in string.gmatch(str,"[ ^ \t ]+")
  return cont
end
local function err(str)
  term.setTextColor(er)
  print(str)
  term.setTextColor(txt)
end
local commands = {
  ["exit"] = function() running = false end;
}

--# Main loop
while running do
  local inp = read(nil,hist)
  if inp:sub(1,1) == "/" and commands[inp:sub(2,#inp)] then
	commands[inp:sub(2,#inp)]()
  else
	err("command unknown")
  end
  local prep = prepare(inp)

  if fs.exists(inp[1]) then
	shell.run(inp)
  else
	err("file not found")
  end
  table.insert(hist,inp)
end
Should work but i don't know if the "regex" is correct.

Ok. Thanks. I will take a look.