Subnet command (#17)

* Started working on subnets

* Basic version of the subnet command

* Improved subnet command

* almost done with subnets

* improve positioning
This commit is contained in:
Borys Levytskyi
2021-01-16 11:33:45 +02:00
committed by GitHub
parent 0cd9c8049b
commit 478ecbfb60
24 changed files with 659 additions and 332 deletions

View File

@@ -0,0 +1 @@
.debug-indicators { position: absolute; top: 1em; left: 1em}

View File

@@ -1,5 +1,6 @@
import AppState from "../AppState";
import React from "react";
import './DebugIndicators.css';
function DebugIndicators(props: {appState: AppState}) {
@@ -21,8 +22,8 @@ function DebugIndicators(props: {appState: AppState}) {
if(list.length == 0)
return null;
return <div>
{list.map(i => <span>{i}&nbsp;</span>)}
return <div className="debug-indicators">
{list.map(i => <span title={i}>[{i.substring(0,1)}]&nbsp;</span>)}
</div>
}

View File

@@ -1,5 +1,5 @@
.top-links { position: absolute; right: 10px; top: 10px; list-style-type: none; margin: 0 }
.top-links { position: absolute; right: 1em; top: 1em; list-style-type: none; margin: 0 }
.top-links li { float: left; }
.top-links a { display: inline-block; padding: 10px 15px}
.top-links .icon { margin-right: 5px; vertical-align: middle; }

View File

@@ -7,6 +7,7 @@ import ErrorResultView from './components/ErrorResultView';
import HelpResultView from './components/HelpResultView';
import TextResultView from './components/TextResultView';
import WhatsnewResultView from './components/WhatsNewResultView';
import {STARTUP_COMMAND_KEY} from './startup';
const shellModule = {
setup: function(appState: AppState, cmd: CmdShell) {
@@ -29,6 +30,35 @@ const shellModule = {
appState.addCommandResult(c.input, <TextResultView text={`Debug Mode: ${appState.debugMode}`}/>);
});
if(appState.env !== 'prod') {
// Default command for development purposes
cmd.command({
canHandle: (s: string) => s.indexOf('default') === 0,
handle: (s: CommandInput) => {
const executeCommand = (c: string) => {
console.log(c);
if(c.length === 0) {
return "Default comand: " + localStorage.getItem(STARTUP_COMMAND_KEY);
}
else if(c === 'clear') {
localStorage.removeItem(STARTUP_COMMAND_KEY);
return "Default startup command cleared";
}
localStorage.setItem(STARTUP_COMMAND_KEY, c);
return `Default startup command saved: ${c}`;
};
const command = s.input.substring(7).trim();
const result = executeCommand(command);
appState.addCommandResult(s.input, <TextResultView text={result} />);
}
});
};
cmd.onError((input: string, err: Error) => appState.addCommandResult(input, <ErrorResultView errorMessage={err.toString()} />));
}
}

View File

@@ -3,12 +3,16 @@ import hash from '../core/hash';
import AppState from './AppState';
import { Env } from './interfaces';
import appStateStore from './appStateStore';
import CommandLink from '../core/components/CommandLink';
export type StartupAppData = {
appState: AppState,
startupCommands: string[]
}
const STARTUP_COMMAND_KEY = 'StartupCommand';
const DEFAULT_COMMANDS = ['help', '127.0.0.1 192.168.0.0/8', '1|2&6','4 0b1000000 0x80'];
function bootstrapAppData() : StartupAppData {
const env = window.location.host === "bitwisecmd.com" ? 'prod' : 'stage';
@@ -35,7 +39,10 @@ function createAppState(env:string) {
function getStartupCommands(appState : AppState) : string[] {
var hashArgs = hash.getArgs(window.location.hash);
var startupCommands = ['help', '127.0.0.1 192.168.0.0/8', '1|2&6','4 0b1000000 0x80'];
var startupCommands = loadStoredCommands();
if(startupCommands.length == 0)
startupCommands = DEFAULT_COMMANDS;
if(appState.wasOldVersion) {
startupCommands = ["whatsnew"];
@@ -50,6 +57,11 @@ function getStartupCommands(appState : AppState) : string[] {
return startupCommands;
}
function loadStoredCommands() : string[] {
const json = localStorage.getItem(STARTUP_COMMAND_KEY);
return json != null ? [json] : [];
}
function setupLogger(env: Env) {
if(env != 'prod'){
log.setLevel("debug");
@@ -59,4 +71,5 @@ function setupLogger(env: Env) {
}
}
export {STARTUP_COMMAND_KEY};
export default bootstrapAppData;