• Stars
    star
    1,233
  • Rank 36,468 (Top 0.8 %)
  • Language
    TypeScript
  • Created over 4 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CLUI is a collection of JavaScript libraries for building command-driven interfaces with context-aware autocomplete.

CLUI

CLUI is a collection of JavaScript libraries for building command-line interfaces with context-aware autocomplete.

See Demo

Packages

@replit/clui-input

@replit/clui-input implements the logic for mapping text input to suggestions and a potential run function.

import input from '@replit/clui-input';

const rootCommand = {
  commands: {
    open: {
      commands: {
        sesame: {
          run: (args) => {
            /* do something */
          },
        },
      },
    },
  },
};

const update = input({
  command: rootCommand,
  onUpdate: (updates) => {
    /* Update #1: `updates.options` will be
     * [
     *   {
     *     "value": "open",
     *     "inputValue": "open",
     *     "searchValue": "o",
     *     "cursorTarget": 4
     *   }
     * ]
     */

    /* Update #2: `updates.options` will be
     * [
     *   {
     *     "value": "sesame",
     *     "inputValue": "open sesame",
     *     "searchValue": "s",
     *     "cursorTarget": 12
     *   }
     * ]
     */
  },
});

/* Update #1 */
update({ value: 'o', index: 1 });

/* Update #2 */
update({ value: 'open s', index: 6 });

When the input matches a command with a run function, the onUpdate callback will include a reference to it.

const update = input({
  command: rootCommand,
  onUpdate: (updates) => {
    // call or store reference to `updates.run` based on user interaction
  },
});

update({ value: 'open sesame', index: 6 });

@replit/clui-input a framework agnostic primitive that can be wrapped by more specific framework or application code (like a react hook). If using react you will most likey want to keep the result of onUpdate in a state object. For managing dropdown selection UX I highly recommend downshift.

@replit/clui-session

@replit/clui-session implements the logic for rendering a list of react children. For building a CLI-style interfaces this can be useful for adding and removing lines when the prompt is submitted.

import React from 'react'
import { render } from 'react-dom'
import Session, { Do } from '@replit/clui-session';

/* `Do` is a helper that exposes the `item` prop
 * You will most likey render your own component
 * which will get `item` injected as a prop so 
 * that component can call `item.next` based
 * on specific application logic
 */
render(
  <Session>
    <Do>
      {item => <button onClick={item.next}>next 1</button>}
    </Do>
    <Do>
      {item => <button onClick={item.next}>next 2</button>}
    </Do>
    <Do>
      {item => <button onClick={item.next}>next 3</button>}
    </Do>
  </Session>,
  document.getElementById('root'),
);

@replit/clui-gql

@replit/clui-gql is a utility library for building CLUI commands from GraphQL introspection data.

Install

npm install @replit/clui-gql

Usage

To create a tree of CLUI commands call toCommand and then visit each command to define a run function.

import { toCommand, visit } from '@replit/clui-gql';
import { introspectionFromSchema } from 'graphql';
import schema from './your-graphql-schema';

// on server
const introspection = introspectionFromSchema(schema);

// on client
const introspection = makeNetworkRequestForData();

// Create a command tree from graphql introspection data. This could be done on
// the server or the client.
const root = toCommand({
  // 'query' or 'mutation'
  operation: 'query',

  // The name of the graphql type that has the fields that act as top level commands
  rootTypeName: 'CluiCommands'

  // the path at which the above type appears in the graph
  mountPath: ['cli', 'admin'],

  // GraphQL introspection data
  introspectionSchema: introspection.__schema,

  // Configure fields and fragments for the output of the GraphQL operation string
  output: () => ({
    fields: '...Output',
    fragments: `
      fragment Output on YourOutputTypes {
        ...on SuccessOutput {
          message
        }
        ...on ErrorOutput {
          error
        }
      }`,
  }),
});

// Define some application specific behavior for when a command is `run`
visit(root, (command) => {
  if (command.outputType !== 'YourOutputTypes') {
    // If command does not match an output type you may want do something different.
    By omitting the run function the command acts as a namespace for sub-commands.
    return;
  }

  command.run = (options) => {
    return <OutputView command={command} options={options} />
  }
}

'parseArgs' is a helper for working with args

import { parse } from 'graphql';
import { parseArgs } from '@replit/clui-gql';

const OutputView = (props) => {
  // CLIU command generated from graphql
  const { command } = props;

  // CLUI args
  const { args } = props.options;

  const parsed = parseArgs({ command, args });

  // Handle state for submitting command based on parsed args

  if (parsed.missing.required) {
    return <HandleMissingArgs />;
  }

  if (parsed.missing.optional) {
    return <PotentiallyShowOptinalInputs />;
  }

  if (command.query) {
    graphQLClient.query(parse(command.query), { variables: parsed.variables })
  } else if (command.mutation) {
    graphQLClient.mutate(parse(command.mutation), { variables: parsed.variables })
  }

  // ...some component to communicate above state
}

More Repositories

1

kaboom

💥 JavaScript game library
TypeScript
2,376
star
2

upm

â • Universal Package Manager - Python, Node.js, Ruby, Emacs Lisp.
Go
1,021
star
3

ReplitLM

Inference code and configs for the ReplitLM model family
Python
900
star
4

polygott

Base Docker image for the Repl.it evaluation server
Shell
386
star
5

codemirror-vim

Vim keybindings for CM6
JavaScript
244
star
6

prybar

Pry open those interpreters.
Go
242
star
7

play

The easiest way to start coding games and graphics projects in Python
Python
182
star
8

replit-py

A helpful Python package that helps you build excellent things inside Repls! 💻
Python
151
star
9

crosis

A JavaScript client that speaks Replit's container protocol
TypeScript
109
star
10

codemirror-interact

TypeScript
92
star
11

ReplitClient.js

A JavaScript client library used to connect to the server-side code execution service
67
star
12

replit-vscode

Replit in vscode
TypeScript
54
star
13

evalbot

A bot that speaks code
JavaScript
48
star
14

codemirror-indentation-markers

A CodeMirror extension that renders indentation markers
TypeScript
44
star
15

repl.sh

Sometimes you need a shell (alpha release)
JavaScript
37
star
16

extensions

A client library for the Replit Extensions API
TypeScript
33
star
17

Codemirror-CSS-color-picker

A codemirror extension that adds a color picker input next to CSS color values. Development happens on Replit, just fork and hit run! https://replit.com/@util/Codemirror-CSS-color-picker
TypeScript
30
star
18

codemirror-vscode-keymap

VSCode keyboard shortcuts for CodeMirror 6
TypeScript
29
star
19

nixmodules

Nix
27
star
20

codemirror-lang-svelte

Svelte language support for CodeMirror 6
TypeScript
26
star
21

codemirror-minimap

Minimap extension for Codemirror 6
TypeScript
25
star
22

river

Long-lived Streaming Remote Procedure Calls
TypeScript
24
star
23

database-go

Go client for Repl.it Database
Go
22
star
24

pyright-extended

pyright with yapf and ruff
Python
20
star
25

nixpkgs-replit

Nix
19
star
26

rfbproxy

An RFB proxy that enables WebSockets and audio.
Nix
19
star
27

blog

the code behind https://blog.replit.com/
EJS
19
star
28

replit-code-exec

A library that allows interacting with Replit's code-exec API
Python
18
star
29

protocol

The Protocol definition file and language bindings
JavaScript
17
star
30

codemirror-emacs

Emacs keybindings for CM6
TypeScript
14
star
31

express-router-async

Creates an express router augmented with promise handling routes
JavaScript
13
star
32

replbox

JavaScript
12
star
33

codemirror-lang-nix

A Nix language mode for CodeMirror 6
TypeScript
11
star
34

kaboomware

TypeScript
9
star
35

go-replidentity

Go implementation of Repl Identity
Go
9
star
36

extensions-react

Replit Extensions React Client
TypeScript
9
star
37

nix-editor

an automatic editor for replit.nix files
Rust
8
star
38

replit-ai-python

The library for Replit AI
Python
7
star
39

repl-auth

Allow your users to sign in with Replit!
JavaScript
7
star
40

audio-libs

Audio bindings for javascript
Python
6
star
41

toml-editor

Rust
6
star
42

codemirror-lang-csharp

TypeScript
6
star
43

homebrew-tap

Homebrew tap for Repl.it open-source.
Ruby
5
star
44

replit-node

A node.js library that helps you build excellent things inside Repls!
TypeScript
5
star
45

replit-ai-modelfarm-typescript

TypeScript
4
star
46

nixsysdeps

A mapping from language packages to nixpkgs system dependencies
Shell
4
star
47

codemirror-lang-solidity

CodeMirror 6 extension for Solidity language support and syntax highlighting
TypeScript
4
star
48

ztoc-rs

SOCI ztoc index builder
Rust
4
star
49

alcor

Serialize and hydrate complex javascript objects
TypeScript
4
star
50

replkit

TypeScript
3
star
51

kaboomsite

Website for Kaboom.js
JavaScript
2
star
52

example-repltweet

An example of using replit-py for exploring the world of web applications! 🗺
JavaScript
2
star
53

abcd-amasad

abcd-amasad created by GitHub Classroom
HTML
2
star
54

scoop-bucket

Scoop bucket for Repl.it open-source.
2
star
55

heroku-bot

A bot that responds to a slack slash command with a diff of commits going out to heroku
JavaScript
1
star
56

ruspty

PTY for Bun (and Node) through Rust FFI
JavaScript
1
star
57

repl-auth-node

Nodejs client for Repl Auth functions!
JavaScript
1
star
58

protocol-go

Mirror for Go package for repl.it protocol. Actual package here https://github.com/replit/protocol/
1
star