This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KernelDeimos
committed
May 24, 2023
1 parent
e164032
commit 01f1f7a
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import path_ from "path-browserify"; | ||
|
||
// DRY: also done in many other places | ||
const resolve = (ctx, relPath) => { | ||
if ( relPath.startsWith('/') ) { | ||
return relPath; | ||
} | ||
console.log('wrong context?', ctx); | ||
return path_.resolve(ctx.vars.pwd, relPath); | ||
} | ||
|
||
export class FileCompleter { | ||
async getCompetions (ctx, inputState) { | ||
const { puterShell } = ctx.externs; | ||
|
||
let path = resolve(ctx, inputState.input); | ||
let dir = path_.dirname(path); | ||
let base = path_.basename(path); | ||
|
||
const completions = []; | ||
|
||
const result = await puterShell.command('list', { path: dir }); | ||
for ( const item of result ) { | ||
if ( item.name.startsWith(base) ) { | ||
completions.push(item.name.slice(base.length)); | ||
} | ||
} | ||
|
||
return completions; | ||
} | ||
} |