This is an old revision of the document!
Python scripting
Choose Script → Run and select a .py file. Python runs separately from the desktop UI. The application passes a private, per-instance local connection token and the originating tab ID; changing focus does not retarget the script. Cancellation terminates the script process and leaves the connection open.
Linux uses configured/system Python 3. Windows packages include a private Python runtime. Select a different interpreter under Global Settings → Automation if needed. The lantern module uses only the standard library.
from lantern import app tab = app.GetScriptTab() tab.Screen.Send("printf '%s%s\\n' 'terminal-' 'ready'\r") if not tab.Screen.WaitForString("terminal-ready", 5): raise TimeoutError("Endpoint did not respond") print(tab.Caption, tab.Screen.Rows, tab.Screen.Columns)
Build test prompts from pieces so a wait does not match its own echoed command line. A screen send records the incoming-stream position before transmission, so an immediate reply is retained for the following wait.
Included interface
app.Version,app.Arguments.Count/GetArg(0),app.GetScriptTab(),app.GetActiveTab(),app.GetTabCount(),app.GetTab(1),app.Sleep(milliseconds)andapp.Quit().- Tabs:
Caption, one-basedIndex,Screen,Session,Activate(),Clone(),Close(),ConnectSftp(),ResetCaption(). - Screen:
Rows,Columns, one-basedCurrentRow/CurrentColumn,Selection,Send(text), binarySendBytes(data),Get/Get2(top,left,bottom,right),Clear(),SendKeys(),SendSpecial(),WaitForCursor(),WaitForString(),WaitForStrings()andReadString(). - Matching:
IgnoreCase, captureIgnoreEscape,SynchronousandMatchIndex. Wait timeouts default to seconds; zero waits until match/disconnect/cancellation.WaitForStringsreturns one-based index or zero on timeout;WaitForStringreturns a boolean.ReadStringexcludes the matched delimiter and returns empty text on timeout. - Session:
Connected,Logging,LogFileName,Config,Disconnect(),Connect(profile),ConnectInTab(profile), andLog(enabled, append, raw). - Configuration:
GetOption(key),SetOption(key,value)andSave(). Keys are the typed application keys insrc/config.cpp, such asfontSize,logPath,host,portandkeyFile. - Clipboard:
app.Clipboard.Text. - Dialogs:
app.Dialog.MessageBox(text,title),Prompt(text,title,default,password)andFileOpenDialog(title).
Get2 retains line separators; Get concatenates lines. Closed/locked sessions and invalid coordinates produce explicit errors. A session disconnected while waiting raises LanternError. Capture is bounded; truncation raises an error rather than silently dropping the beginning of a response.
The comprehensive SCRIPTING-API.md defines the larger API contract. Members outside the included interface above are not supplied by this release. Lua can be added against the same application API without changing the terminal or transport engine.
