Skip to content

2a. Terminal View

Mengting Yan edited this page Apr 20, 2020 · 2 revisions

Kui Provides a fully-featured terminal. In response to certain commands, Kui augments the basic ASCII art presented by those commands with graphics.

Basic Layout

The UI of Terminal is divided into Command Blocks. Each of the Command Block contains Command Input and Output.

Command Response

If your command handler returns one the following data types, it will be rendered in the Kui Terminal view: string, boolean, and Table. More complex data types can be presented in custom views. For example, Kui includes a Sidecar view component, some examples of which are shown on the top page. This page focuses on command handlers that are intended to be presented in the Terminal.

Option 1: Return a string to terminal

export const printString = () => 'Hello!'

Option 2: Return a boolean to terminal

export const printOK = () => true

Option 3: Return a Table to terminal

To render a table in terminal, your command handler will return a Table model. Kui then visualizes the table for you using a built-in view. This built-in view uses the Carbon Components library. Here's an example of returning a 2x2 Table:

import { Table } from '@kui-shell/core'

// shown in image labed B
export const printTable = (): Table => ({
  header: { name: 'Column1', attributes: [{ value: 'Column2' }]},
  body: [
    { name: 'Row1Column1', attributes: [{ value: 'Row1Column2' }]},
    { name: 'Row2Column1', attributes: [{ value: 'Row2Column2' }]}
  ]
})

In this example code, printString, printOK and printTable are Kui Command Handlers that happen to take no arguments. For more information on Command Handlers, how they can consume required and optional parameters, and how to link your handler to a particular command-line string, consult the Kui Command Documentation.