• This repository has been archived on 30/Apr/2024
  • Stars
    star
    1,240
  • Rank 37,884 (Top 0.8 %)
  • Language
    TypeScript
  • Created almost 5 years ago
  • Updated 7 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,524
star
2

upm

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

ReplitLM

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

polygott

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

codemirror-vim

Vim keybindings for CM6
JavaScript
278
star
6

prybar

Pry open those interpreters.
Go
245
star
7

play

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

replit-py

A helpful Python package that helps you build excellent things inside Repls! πŸ’»
Python
156
star
9

rippkgs

A CLI for indexing and searching packages in Nix expressions
Rust
137
star
10

crosis

A JavaScript client that speaks Replit's container protocol
TypeScript
111
star
11

codemirror-interact

TypeScript
101
star
12

ReplitClient.js

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

replit-vscode

Replit in vscode
TypeScript
57
star
14

codemirror-indentation-markers

A CodeMirror extension that renders indentation markers
TypeScript
53
star
15

evalbot

A bot that speaks code
JavaScript
48
star
16

codemirror-minimap

Minimap extension for Codemirror 6
TypeScript
42
star
17

river

🌊 Long-lived Streaming Remote Procedure Calls
TypeScript
39
star
18

nixmodules

Nix
38
star
19

repl.sh

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

database-node

Node.js client for Replit Database
TypeScript
37
star
21

extensions

A client library for the Replit Extensions API
TypeScript
34
star
22

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
33
star
23

codemirror-lang-svelte

Svelte language support for CodeMirror 6
TypeScript
30
star
24

codemirror-vscode-keymap

VSCode keyboard shortcuts for CodeMirror 6
TypeScript
30
star
25

pyright-extended

pyright with yapf and ruff
Python
23
star
26

database-go

Go client for Repl.it Database
Go
23
star
27

codemirror-emacs

Emacs keybindings for CM6
TypeScript
21
star
28

nixpkgs-replit

Nix
20
star
29

rfbproxy

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

replit-code-exec

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

blog

the code behind https://blog.replit.com/
EJS
18
star
32

protocol

The Protocol definition file and language bindings
JavaScript
17
star
33

express-router-async

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

codemirror-lang-nix

A Nix language mode for CodeMirror 6
TypeScript
12
star
35

replbox

JavaScript
12
star
36

extensions-react

Replit Extensions React Client
TypeScript
10
star
37

kaboomware

TypeScript
9
star
38

go-replidentity

Go implementation of Repl Identity
Go
9
star
39

nix-editor

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

toml-editor

Rust
8
star
41

replit-ai-python

The library for Replit AI
Python
7
star
42

ruspty

PTY for Bun (and Node) through Rust FFI
JavaScript
7
star
43

repl-auth

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

audio-libs

Audio bindings for javascript
Python
6
star
45

replit-ai-modelfarm-typescript

TypeScript
5
star
46

codemirror-lang-solidity

CodeMirror 6 extension for Solidity language support and syntax highlighting
TypeScript
5
star
47

replit-node

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

codemirror-lang-csharp

TypeScript
5
star
49

replkit

TypeScript
4
star
50

kaboomsite

Website for Kaboom.js
JavaScript
4
star
51

nixsysdeps

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

ztoc-rs

SOCI ztoc index builder
Rust
4
star
53

alcor

Serialize and hydrate complex javascript objects
TypeScript
4
star
54

river-babel

cross-language testing for @replit/river
TypeScript
3
star
55

replit_rtld_loader

A dynamic runtime shared library loader for Repls that supports system dependency assistance and handles binary segregation by Nix channel.
C
3
star
56

example-repltweet

An example of using replit-py for exploring the world of web applications! πŸ—Ί
JavaScript
2
star
57

abcd-amasad

abcd-amasad created by GitHub Classroom
HTML
2
star
58

replit-object-storage-python

The library for Replit Object Storage
Python
2
star
59

protocol-go

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

scoop-bucket

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

heroku-bot

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

overlang

Nix overlays for every programming need
Nix
1
star
63

replit-object-storage-typescript

The TypeScript library for Replit Object Storage
TypeScript
1
star
64

pid2-github-import-test

1
star
65

repl-auth-node

Nodejs client for Repl Auth functions!
JavaScript
1
star