Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: deprecate @urbit/api #3

Merged
merged 1 commit into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ import { _dark, _light } from '@tlon/indigo-react';

import 'xterm/css/xterm.css';

import {
scrySessions
} from '@urbit/api';

import { ThemeProvider } from 'styled-components';
import { Tabs } from './Tabs';
import Buffer from './Buffer';
import { DEFAULT_SESSION } from './constants';
import { showSlog } from './lib/blit';
import { InfoButton } from './InfoButton';
import { scrySessions } from './lib/utils';

const initSessions = async () => {
const response = await api.scry(scrySessions());
Expand Down
5 changes: 3 additions & 2 deletions ui/Buffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import bel from './lib/bel';
import api from './api';

import {
Belt, pokeTask, pokeBelt
} from '@urbit/api';
pokeTask, pokeBelt
} from './lib/utils'
import { Session } from './state';
import { useCallback, useEffect, useRef } from 'react';
import useTermState from './state';
Expand All @@ -16,6 +16,7 @@ import { makeTheme } from './lib/theme';
import { showBlit, csi, hasBell } from './lib/blit';
import { DEFAULT_SESSION, RESIZE_DEBOUNCE_MS, RESIZE_THRESHOLD_PX } from './constants';
import { retry } from './lib/retry';
import { Belt } from 'lib/types';

const termConfig: ITerminalOptions = {
logLevel: 'warn',
Expand Down
4 changes: 2 additions & 2 deletions ui/Tab.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DEFAULT_SESSION } from './constants';
import React, { useCallback, useEffect } from 'react';
import React, { useCallback } from 'react';
import useTermState, { Session } from './state';
import api from './api';
import { pokeTask } from '@urbit/api';
import { pokeTask } from './lib/utils';
import { DelayedSpinner as Spinner } from './Spinner';

interface TabProps {
Expand Down
2 changes: 1 addition & 1 deletion ui/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import TermApp from './App';
import { preSig } from '@urbit/api';
import { preSig } from '@urbit/aura';
import cookies from 'browser-cookies';

function authRedirect() {
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/blit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Terminal } from 'xterm';
import { saveAs } from 'file-saver';
import { Blit, Stub, Stye } from '@urbit/api';
import { Blit, Stub, Stye } from '../lib/types';
import { stye } from '../lib/stye';

export const csi = (cmd: string, ...args: number[]) => {
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/stye.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Deco, Stye, Tint } from '@urbit/api';
import { Deco, Stye, Tint } from './types';

const tint = (t: Tint) => {
switch (t) {
Expand Down
61 changes: 61 additions & 0 deletions ui/lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// outputs
//

export type TermUpdate =
| Blit;

export type Tint =
| null
| 'r' | 'g' | 'b' | 'c' | 'm' | 'y' | 'k' | 'w'
| { r: number, g: number, b: number };

export type Deco = null | 'br' | 'un' | 'bl';

export type Stye = {
deco: Deco[],
back: Tint,
fore: Tint
};

export type Stub = {
stye: Stye,
text: string[]
}

export type Blit =
| { bel: null } // make a noise
| { clr: null } // clear the screen
| { hop: number | { x: number, y: number } } // set cursor col/pos
| { klr: Stub[] } // put styled
| { mor: Blit[] } // multiple blits
| { nel: null } // newline
| { put: string[] } // put text at cursor
| { sag: { path: string, file: string } } // save to jamfile
| { sav: { path: string, file: string } } // save to file
| { url: string } // activate url
| { wyp: null } // wipe cursor line

// inputs
//

export type Bolt =
| string
| { aro: 'd' | 'l' | 'r' | 'u' }
| { bac: null }
| { del: null }
| { hit: { x: number, y: number } }
| { ret: null }

export type Belt =
| Bolt
| { mod: { mod: 'ctl' | 'met' | 'hyp', key: Bolt } }
| { txt: Array<string> }

export type Task =
| { belt: Belt }
| { blew: { w: number, h: number } }
| { hail: null }
| { open: { term: string, apps: Array<{ who: string, app: string }> } }
| { shut: null }

export type SessionTask = { session: string } & Task
2 changes: 1 addition & 1 deletion ui/lib/useAddSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '../constants';
import useTermState from '../state';
import api from '../api';
import { pokeTask } from '@urbit/api';
import { pokeTask } from './utils';
import { useCallback } from 'react';

export const useAddSession = () => {
Expand Down
19 changes: 19 additions & 0 deletions ui/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Poke, Scry } from '@urbit/http-api';
import { Belt, Task, SessionTask } from './types';

export const pokeTask = (session: string, task: Task): Poke<SessionTask> => ({
app: 'herm',
mark: 'herm-task',
json: { session, ...task }
});

export const pokeBelt = (
session: string,
belt: Belt
): Poke<SessionTask> => pokeTask(session, { belt });

//NOTE scry will return string[]
export const scrySessions = (): Scry => ({
app: 'herm',
path: `/sessions`
});
Loading