-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get the TLDR Pages extension working again
- Loading branch information
1 parent
e83af40
commit 267057f
Showing
18 changed files
with
1,110 additions
and
126 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
/* | ||
* Copyright 2020 Simon Edwards <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file. | ||
*/ | ||
import sh from 'shelljs'; | ||
|
||
if ( ! sh.test('-d', 'data')) { | ||
sh.echo("Downloading TLDR Pages data files..."); | ||
sh.exec('download --extract --out data http://tldr-pages.github.io/assets/tldr.zip'); | ||
sh.rm('-r', 'data/pages.*'); | ||
sh.mv('data/index.json', 'data/pages/index.json'); | ||
sh.echo("Done downloading TLDR Pages data."); | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
/* | ||
* Copyright 2020 Simon Edwards <[email protected]> | ||
* Copyright 2022 Simon Edwards <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file. | ||
*/ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import * as path from 'node:path'; | ||
import * as fs from 'node:fs'; | ||
|
||
|
||
export interface PageInfo { | ||
|
@@ -29,15 +29,17 @@ enum ParseState { | |
|
||
export class PageDatabase { | ||
|
||
private _commandNameList: string[] = []; | ||
private _pageInfoList: PageInfo[] = []; | ||
private _pageInfoCache = new Map<string, PageInfo>(); | ||
#commandNameList: string[] = []; | ||
#pageInfoList: PageInfo[] = []; | ||
#pageInfoCache = new Map<string, PageInfo>(); | ||
#databasePath: string; | ||
|
||
constructor(private _databasePath: string) { | ||
constructor(databasePath: string) { | ||
this.#databasePath = databasePath; | ||
} | ||
|
||
async loadIndex(): Promise<void> { | ||
const pagesIndexPath = path.join(this._databasePath, "index.json"); | ||
const pagesIndexPath = path.join(this.#databasePath, "index.json"); | ||
const indexJSONString = await fs.promises.readFile(pagesIndexPath, {encoding: "utf8"}); | ||
const pageIndex = JSON.parse(indexJSONString); | ||
|
||
|
@@ -66,45 +68,45 @@ export class PageDatabase { | |
} | ||
} | ||
} | ||
this._commandNameList = commandList; | ||
this._pageInfoList = pageInfoList; | ||
this.#commandNameList = commandList; | ||
this.#pageInfoList = pageInfoList; | ||
} | ||
|
||
getCommandNames(): string[] { | ||
return this._commandNameList; | ||
return this.#commandNameList; | ||
} | ||
|
||
async getPageInfoByName(commandName: string, platform: string): Promise<PageInfo> { | ||
const info = this._pageInfoList.find(info => info.command === commandName && info.platform === platform); | ||
const info = this.#pageInfoList.find(info => info.command === commandName && info.platform === platform); | ||
if (info == null) { | ||
return null; | ||
} | ||
return this._getPageInfoByInfo(info); | ||
return this.#getPageInfoByInfo(info); | ||
} | ||
|
||
async getPageInfoByIndex(commandIndex: number): Promise<PageInfo> { | ||
const info = this._pageInfoList[commandIndex]; | ||
return this._getPageInfoByInfo(info); | ||
const info = this.#pageInfoList[commandIndex]; | ||
return this.#getPageInfoByInfo(info); | ||
} | ||
|
||
private async _getPageInfoByInfo(commandInfo: PageInfo): Promise<PageInfo> { | ||
if (this._pageInfoCache.has(commandInfo.name)) { | ||
return this._pageInfoCache.get(commandInfo.name); | ||
async #getPageInfoByInfo(commandInfo: PageInfo): Promise<PageInfo> { | ||
if (this.#pageInfoCache.has(commandInfo.name)) { | ||
return this.#pageInfoCache.get(commandInfo.name); | ||
} | ||
await this._fillInExamples(commandInfo); | ||
this._pageInfoCache.set(commandInfo.name, commandInfo); | ||
await this.#fillInExamples(commandInfo); | ||
this.#pageInfoCache.set(commandInfo.name, commandInfo); | ||
return commandInfo; | ||
} | ||
|
||
private async _fillInExamples(commandInfo: PageInfo): Promise<void> { | ||
const pagePath = path.join(this._databasePath, commandInfo.platform, `${commandInfo.name}.md`); | ||
async #fillInExamples(commandInfo: PageInfo): Promise<void> { | ||
const pagePath = path.join(this.#databasePath, commandInfo.platform, `${commandInfo.name}.md`); | ||
const pageString = await fs.promises.readFile(pagePath, { encoding: "utf8" }); | ||
const {description, examples } = this._parsePage(pageString); | ||
const {description, examples } = this.#parsePage(pageString); | ||
commandInfo.description = description; | ||
commandInfo.examples = examples; | ||
} | ||
|
||
private _parsePage(pageString: string): { description: string; examples: CommandExample[]; } { | ||
#parsePage(pageString: string): { description: string; examples: CommandExample[]; } { | ||
const lines = pageString.split("\n"); | ||
let state: ParseState = ParseState.PROLOGUE; | ||
|
||
|
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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
/* | ||
* Copyright 2020 Simon Edwards <[email protected]> | ||
* Copyright 2022 Simon Edwards <[email protected]> | ||
* | ||
* This source code is licensed under the MIT license which is detailed in the LICENSE.txt file. | ||
*/ | ||
import { ExtensionContext, Logger, ListPickerOptions } from '@extraterm/extraterm-extension-api'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { PageDatabase } from './PageDatabase'; | ||
import * as path from 'node:path'; | ||
import { PageDatabase } from './PageDatabase.js'; | ||
|
||
|
||
let log: Logger = null; | ||
|
@@ -30,7 +29,7 @@ async function showCommandList(): Promise<void> { | |
selectedItemIndex: 0, | ||
}; | ||
|
||
const selected = await context.window.activeTerminal.tab.showListPicker(allCommandsOptions); | ||
const selected = await context.activeTerminal.tab.showListPicker(allCommandsOptions); | ||
if (selected == null) { | ||
return; | ||
} | ||
|
@@ -42,9 +41,9 @@ async function showCommandList(): Promise<void> { | |
items: info.examples.map(ex => ex.description), | ||
selectedItemIndex: 0, | ||
}; | ||
const selectedExample = await context.window.activeTerminal.tab.showListPicker(commandOptions); | ||
const selectedExample = await context.activeTerminal.tab.showListPicker(commandOptions); | ||
if (selectedExample == null) { | ||
return; | ||
} | ||
context.window.activeTerminal.type(info.examples[selectedExample].commandLine); | ||
context.activeTerminal.type(info.examples[selectedExample].commandLine); | ||
} |
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
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
Oops, something went wrong.