Skip to content

Commit

Permalink
Began adding editor
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Oct 13, 2024
1 parent 0acf597 commit 331d8bc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 25 deletions.
30 changes: 30 additions & 0 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import $ from 'jquery';
import { update } from './explorer.js';
import { cd, cwd, resolve } from '@zenfs/core/emulation/path.js';
import { fs } from '@zenfs/core';

export function switchTab(name: string): void {
$('.tab').hide();
$('#' + name)
.filter('.tab')
.show();

if (name == 'explorer') {
update();
}
}

export function openPath(dir: string, fromShell: boolean = false): void {
if (fs.statSync(dir).isDirectory()) {
cd(dir);
$('#location').val(cwd);
return;
}

if (fromShell) {
throw new Error(`Error: ENOTDIR: File is not a directory, '${resolve(dir)}'`);
}

switchTab('editor');
$('#editor .content').text(fs.readFileSync(dir, 'utf-8'));
}
15 changes: 2 additions & 13 deletions src/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import { fs } from '@zenfs/core';
import { cwd, join, cd, resolve } from '@zenfs/core/emulation/path.js';
import { cwd, join } from '@zenfs/core/emulation/path.js';
import $ from 'jquery';
import { formatCompact } from 'utilium';
import { cloneTemplate } from 'utilium/dom.js';
import { openPath } from './common.js';

export const location = $<HTMLInputElement>('#location');

export function openPath(dir: string, fromShell: boolean = false): void {
if (fs.statSync(dir).isDirectory()) {
cd(dir);
$('#location').val(cwd);
return;
}

if (fromShell) {
throw new Error(`Error: ENOTDIR: File is not a directory, '${resolve(dir)}'`);
}
}

const endsWithLetter = /[^\d]$/;

function createEntry(name: string) {
Expand Down
7 changes: 7 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<div id="nav">
<button name="config">Config</button>
<button name="explorer">Explorer</button>
<button name="editor">Editor</button>
<button name="terminal">Terminal</button>
<input id="location" value="/" placeholder="Path" />
</div>
Expand Down Expand Up @@ -53,6 +54,12 @@
</template>
</ul>

<div id="editor" class="tab" style="display: none">
<strong class="title">Editor</strong>

<textarea class="content"></textarea>
</div>

<div id="terminal" class="tab" style="display: none">
<div id="terminal-container"></div>
</div>
Expand Down
14 changes: 3 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@ import './styles.css';

import $ from 'jquery';
import './config.js';
import { update, openPath, location } from './explorer.js';
import { update, location } from './explorer.js';
import './shell.js';
import { cwd, isAbsolute } from '@zenfs/core/emulation/path.js';
import { fs } from '@zenfs/core';
import { openPath, switchTab } from './common.js';

// Switching tabs
$<HTMLButtonElement>('#nav button').on('click', e => {
$('.tab').hide();
$('#' + e.target.name)
.filter('.tab')
.show();

if (e.target.name == 'explorer') {
update();
}
});
$<HTMLButtonElement>('#nav button').on('click', e => switchTab(e.target.name));

location.on('change', () => {
const value = location.val() ?? '';
Expand Down
2 changes: 1 addition & 1 deletion src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as path from '@zenfs/core/emulation/path.js';
import chalk from 'chalk';
import $ from 'jquery';
import { createShell } from 'utilium/shell.js';
import { openPath } from './explorer.js';
import { openPath } from './common.js';

const terminal = new Terminal({
convertEol: true,
Expand Down
12 changes: 12 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ select {
padding: 0.25em;
}

textarea:focus,
input:focus {
outline: none;
}

#location {
padding: 0.25em 1em;
border-radius: 0.5em;
Expand Down Expand Up @@ -146,6 +151,13 @@ select {
}
}

#editor textarea.content {
position: absolute;
inset: 3em 1em 1em 1em;
border-radius: 0.5em;
border: none;
}

#terminal-container {
position: absolute;
inset: 1em;
Expand Down

0 comments on commit 331d8bc

Please sign in to comment.