Skip to content

Commit

Permalink
Make the default output framing behaviour configurable #90
Browse files Browse the repository at this point in the history
  • Loading branch information
sedwards2009 committed May 13, 2018
1 parent 584b2c2 commit 18df30c
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 28 deletions.
2 changes: 2 additions & 0 deletions extraterm/src/Config.ts
Expand Up @@ -29,6 +29,8 @@ export interface GeneralConfig {
showTitleBar?: boolean;

windowConfiguration?: WindowConfiguration;

frameByDefault?: boolean;
}

// This is the format of the user config JSON file as stored on the filesystem.
Expand Down
5 changes: 5 additions & 0 deletions extraterm/src/main_process/Main.ts
Expand Up @@ -446,6 +446,10 @@ function setupConfig(): void {
userStoredConfig.showTitleBar = false;
}

if (userStoredConfig.frameByDefault !== true && userStoredConfig.frameByDefault !== false) {
userStoredConfig.frameByDefault = true;
}

const keyBindingsDir = path.join(__dirname, KEYBINDINGS_DIRECTORY);
const keyBindingsFiles = scanKeyBindingFiles(keyBindingsDir);

Expand Down Expand Up @@ -549,6 +553,7 @@ function setConfigDefaults(config: UserStoredConfig): void {
config.themeSyntax = defaultValue(config.themeSyntax, "default");
config.themeGUI = defaultValue(config.themeGUI, "atomic-dark-ui");
config.showTitleBar = defaultValue(config.showTitleBar, false);
config.frameByDefault = defaultValue(config.frameByDefault, true);

if (config.commandLineActions === undefined) {
const defaultCLA: CommandLineAction[] = [
Expand Down
59 changes: 35 additions & 24 deletions extraterm/src/render_process/Terminal.ts
Expand Up @@ -55,6 +55,7 @@ import { ConfigDatabase, CommandLineAction, injectConfigDatabase, AcceptsConfigD
import * as SupportsClipboardPaste from "./SupportsClipboardPaste";
import * as SupportsDialogStack from "./SupportsDialogStack";
import { ExtensionManager } from './extension/InternalTypes';
import { DeepReadonlyObject, DeepReadonly } from 'extraterm-readonly-toolbox';

type VirtualScrollable = VirtualScrollArea.VirtualScrollable;
type VirtualScrollArea = VirtualScrollArea.VirtualScrollArea;
Expand Down Expand Up @@ -410,7 +411,6 @@ export class EtTerminal extends ThemeableElementBase implements Commandable, Acc

pty.onData((text: string): void => {
this._emulator.write(text);
// FIXME flow control.
});

doLater(() => {
Expand Down Expand Up @@ -438,40 +438,51 @@ export class EtTerminal extends ThemeableElementBase implements Commandable, Acc
this._extensionManager = extensionManager;
}

private _isNoFrameCommand(commandLine: string): boolean {
private _commandNeedsFrame(commandLine: string): boolean {
const cleanCommandLine = commandLine.trim();
if (cleanCommandLine === "") {
return true;
return false;
}

const commandParts = cleanCommandLine.split(/\s+/);
if (this._configManager === null) {
return false;
} else {

const commandLineActions = this._configManager.getConfig(COMMAND_LINE_ACTIONS_CONFIG) || [];
return commandLineActions
.filter( cla => ! cla.frame)
.some( cla => {
if (cla.matchType === 'name') {
const matcherParts = cla.match.split(/\s+/);
for (let i=0; i < matcherParts.length; i++) {
if (i >= commandParts.length) {
return false;
}
if (matcherParts[i] !== commandParts[i]) {
return false;
}
}
return true;
} else {
// regexp
return (new RegExp(cla.match)).test(cleanCommandLine);
}
} );
const commandLineActions: DeepReadonly<CommandLineAction[]> =
this._configManager.getConfig(COMMAND_LINE_ACTIONS_CONFIG) || [];
const frameByDefault = this._configManager.getConfig(GENERAL_CONFIG).frameByDefault;

for (const cla of commandLineActions) {
if (this._commandLineActionMatches(commandLine, cla)) {
return cla.frame;
}
}
return frameByDefault;
}
}

private _commandLineActionMatches(command: string, cla: DeepReadonly<CommandLineAction>): boolean {
const cleanCommandLine = command.trim();
const commandParts = command.trim().split(/\s+/);

if (cla.matchType === 'name') {
const matcherParts = cla.match.split(/\s+/);
for (let i=0; i < matcherParts.length; i++) {
if (i >= commandParts.length) {
return false;
}
if (matcherParts[i] !== commandParts[i]) {
return false;
}
}
return true;
} else {
// regexp
return (new RegExp(cla.match)).test(cleanCommandLine);
}
}

/**
* Get this terminal's title.
*
Expand Down Expand Up @@ -1738,7 +1749,7 @@ export class EtTerminal extends ThemeableElementBase implements Commandable, Acc
cleancommand = trimmed.slice(trimmed.indexOf(" ")).trim();
}

if ( ! this._isNoFrameCommand(cleancommand)) {
if (this._commandNeedsFrame(cleancommand)) {
// Create and set up a new command-frame.
const el = this._createEmbeddedViewerElement();

Expand Down
15 changes: 12 additions & 3 deletions extraterm/src/render_process/settings/FrameSettings.ts
Expand Up @@ -7,7 +7,7 @@ import * as _ from 'lodash';
import Vue from 'vue';

import { FrameSettingsUi, nextId, Identifiable, IdentifiableCommandLineAction} from './FrameSettingsUi';
import { COMMAND_LINE_ACTIONS_CONFIG, ConfigKey, CommandLineAction } from '../../Config';
import { COMMAND_LINE_ACTIONS_CONFIG, ConfigKey, CommandLineAction, GENERAL_CONFIG, GeneralConfig } from '../../Config';
import { Logger, getLogger } from '../../logging/Logger';
import log from '../../logging/LogDecorator';
import { SettingsBase } from './SettingsBase';
Expand All @@ -19,13 +19,13 @@ export class FrameSettings extends SettingsBase<FrameSettingsUi> {
private _log: Logger = null;

constructor() {
super(FrameSettingsUi, [COMMAND_LINE_ACTIONS_CONFIG]);
super(FrameSettingsUi, [GENERAL_CONFIG, COMMAND_LINE_ACTIONS_CONFIG]);
this._log = getLogger(FRAME_SETTINGS_TAG, this);
}

protected _setConfig(key: ConfigKey, config: any): void {
const ui = this._getUi();
if (key === COMMAND_LINE_ACTIONS_CONFIG) {
const ui = this._getUi();
const commandLineActions = <CommandLineAction[]> config;

const cleanCommandLineAction = _.cloneDeep(ui.commandLineActions);
Expand All @@ -37,13 +37,22 @@ export class FrameSettings extends SettingsBase<FrameSettingsUi> {
ui.commandLineActions = updateCLA;
}
}

if (key === GENERAL_CONFIG) {
const generalConfig = <GeneralConfig> config;
ui.frameByDefault = config.frameByDefault ? "true" : "false";
}
}

protected _dataChanged(): void {
const ui = this._getUi();
const commandLineActions = _.cloneDeep(ui.commandLineActions);
stripIds(commandLineActions);
this._updateConfig(COMMAND_LINE_ACTIONS_CONFIG, commandLineActions);

const generalConfig = <GeneralConfig> this._getConfigCopy(GENERAL_CONFIG);
generalConfig.frameByDefault = ui.frameByDefault === "true" ? true : false;
this._updateConfig(GENERAL_CONFIG, generalConfig);
}
}

Expand Down
16 changes: 15 additions & 1 deletion extraterm/src/render_process/settings/FrameSettingsUi.ts
Expand Up @@ -34,6 +34,19 @@ export function nextId(): string {
template: `
<div class="settings-page">
<h2><i class="far fa-window-maximize"></i>&nbsp;&nbsp;Frame Handling Rules</h2>
<div class="form-horizontal">
<div class="form-group">
<label for="tips" class="col-sm-4 control-label">Default action:</label>
<div class="input-group col-sm-4">
<select v-model="frameByDefault" class="form-control">
<option value="true">Frame command output</option>
<option value="false">Do not frame command output</option>
</select>
</div>
</div>
</div>
<table class="table">
<thead v-if="commandLineActions.length !== 0">
<tr><th>Match</th><th>Command</th><th>Frame</th><th></th></tr>
Expand Down Expand Up @@ -68,7 +81,8 @@ export function nextId(): string {
})
export class FrameSettingsUi extends Vue {

commandLineActions: IdentifiableCommandLineAction[];
frameByDefault: "true" | "false" = "true";
commandLineActions: IdentifiableCommandLineAction[] = [];

constructor() {
super();
Expand Down

0 comments on commit 18df30c

Please sign in to comment.