Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:term [2016/02/29 23:40]
payonel [Term API]
api:term [2018/11/15 17:37]
payonel
Line 4: Line 4:
  
 - `term.isAvailable():​ boolean`  ​ - `term.isAvailable():​ boolean`  ​
-  Returns whether the term API is available for use, i.e. whether a primary GPU an screen are present. In other words, whether `term.read` and `term.write` will actually do something. +  Returns whether the term API is available for use, i.e. whether a primary GPU and screen are present. In other words, whether `term.read` and `term.write` will actually do something. 
-- `term.getViewport([window:​table]): number, number, number, number, number, number`  ​+- `term.getViewport():​ number, number, number, number, number, number`  ​
   (new in OpenOS 1.6)   (new in OpenOS 1.6)
   ​   ​
-  Gets the width, height, x offset, y offset, relative x, and relative y values ​of the current terminal or `window` if provided+  Gets the width, height, x offset, y offset, relative x, and relative y values. 
-- `term.gpu([window:​table]): table`  ​+- `term.gpu():​ table`  ​
   (new in OpenOS 1.6)   (new in OpenOS 1.6)
   ​   ​
-  Gets the gpu of the current terminal (or `window` if provided).+  Gets the gpu proxy used by the term api.
 - `term.pull([...]):​ ...`  ​ - `term.pull([...]):​ ...`  ​
   (new in OpenOS 1.6)   (new in OpenOS 1.6)
Line 39: Line 39:
   The `hint` parameter is used for tab completion. It can either be a table with strings or a function that returns a table of strings and takes two parameters, the current text and the position in that text, i.e. the signature of the callback is `function(line:​string,​ pos:​number):​table`.  ​   The `hint` parameter is used for tab completion. It can either be a table with strings or a function that returns a table of strings and takes two parameters, the current text and the position in that text, i.e. the signature of the callback is `function(line:​string,​ pos:​number):​table`.  ​
   The `pwchar` parameter, when given, causes input to be masked using the first char of the given string. For example, providing `"​*"​` will make all entered characters appear as stars. The returned value will still be the actual text inserted, of course.  ​   The `pwchar` parameter, when given, causes input to be masked using the first char of the given string. For example, providing `"​*"​` will make all entered characters appear as stars. The returned value will still be the actual text inserted, of course.  ​
-  The function will return a string if input was successful, ​or `nil` if there was no more input (user pressed Ctrl+D or Ctrl+C ​or the terminal became unavailable).  ​+  The function will return a string if input was successful, `nil` if the pipe was closed ​(^d), or `false` if the pipe was interrupted (^c) 
   //Note//: `io.stdin:​read()` uses this function.  ​   //Note//: `io.stdin:​read()` uses this function.  ​
   //Note 2//: This will return the entered string with the \n (new line character). If you want only the entered string to be returned, use `io.read()`.   //Note 2//: This will return the entered string with the \n (new line character). If you want only the entered string to be returned, use `io.read()`.
Line 45: Line 46:
   Allows writing optionally wrapped text to the terminal starting at the current cursor position, updating the cursor accordingly. It automatically converts tab characters to spaces using `text.detab`. If `wrap` is true, it will automatically word-wrap the text. It will scroll the displayed buffer if the cursor exceeds the bottom of the display area, but *not* if it exceeds the right of the display area (when `wrap` is false).  ​   Allows writing optionally wrapped text to the terminal starting at the current cursor position, updating the cursor accordingly. It automatically converts tab characters to spaces using `text.detab`. If `wrap` is true, it will automatically word-wrap the text. It will scroll the displayed buffer if the cursor exceeds the bottom of the display area, but *not* if it exceeds the right of the display area (when `wrap` is false).  ​
   //Note//: This method respects io redirection. That is to say, `term.write` writes to the same stream as io.stdout   //Note//: This method respects io redirection. That is to say, `term.write` writes to the same stream as io.stdout
-- `term.readKeyboard(ops:​table)` 
  
-  (new in OpenOS 1.6) +- `term.bind(gpu)`
-   +
-  Reads input directly from keyboard events and does not consider io.stdin. This method should only be used when the user specifically wants to bypass stdin and read directly from the keyboard hardware. `ops` is used identically to `ops` as defined in `term.read`. +
-- `term.drawText(value:​string[,​ wrap:​boolean[,​ window:​table]])`+
  
   (new in OpenOS 1.6)  ​   (new in OpenOS 1.6)  ​
  
-  ​Renders ​`value` directly to the gpu bound to the current window or `window` if provided, wrapping vertically if `wrap` at the current cursor position of the window. Use this method to bypass the io stream. Generally, this method should not be used, but rather `term.write`. +  ​Binds a `gpu` proxy (not address) to the terminal. This method is called automatically during boot when the gpu and screen become available. Note that if manually rebinding a terminal to a screen with different width and height, the terminal draw area will be truncated and not maximized. This changes the gpu used in all terminal output, not just via the term api, i.e. `io.write`, `print`, `io.stdout:​write`,​ etc all use the same output stream, and term.bind is used to change the `gpu` used
-- `term.bind(gpu,​ screen, [keyboard, [window:​table]])` +- `term.screen(): ​string`  ​
- +
-  (new in OpenOS 1.6)   +
- +
-  Binds component proxies ​(not addresses`gpu`, `screen`, and `keyboard` ​to the current ​terminal ​window or `window`. This method is called automatically during boot when the gpu and screen become available. Note that if manually rebinding a terminal to a screen with different width and height, the terminal draw area will be truncated and not maximized. +
-- `term.screen([window:​table]): table`  ​+
   (new in OpenOS 1.6)   (new in OpenOS 1.6)
   ​   ​
-  ​Gets the screen of the current ​terminal (or `windowif provided). +  ​Convenience method, simply calls `getScreen` on the terminal's bound gpu (see `term.bind`) 
-- `term.keyboard([window:​table]): table`  ​+- `term.keyboard(): ​string`  ​
   (new in OpenOS 1.6)   (new in OpenOS 1.6)
   ​   ​
-  Gets the keyboard ​of the current ​terminal ​(or `window` if provided).+  Gets the address ​of the keyboard the terminal ​is accepting key events from.
  
  
Line 73: Line 65:
 ----------- -----------
 {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}} {{page>​api:​contents&​noheader&​noeditbutton&​nouser&​nofooter}}
 +