diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-04-09 10:38:37 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 10:38:37 +0900 |
commit | 1656d52d2cefb3846d968c6117484e6aefe7dabe (patch) | |
tree | ab58a99b832d2571e2168f2ee0e328bc12d9580e /src/shared | |
parent | c6c2da8547891b50aef2f08e5f36d258183831ff (diff) | |
parent | 5176643e64d8f4a6be5fc73f0eb48dc65322e496 (diff) |
Merge pull request #730 from ueokande/refactor-console-and-completion
Refactor console and completions
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/Command.ts | 44 | ||||
-rw-r--r-- | src/shared/CompletionType.ts | 7 | ||||
-rw-r--r-- | src/shared/TabFlag.ts | 7 | ||||
-rw-r--r-- | src/shared/messages.ts | 80 |
4 files changed, 130 insertions, 8 deletions
diff --git a/src/shared/Command.ts b/src/shared/Command.ts new file mode 100644 index 0000000..b8c21ce --- /dev/null +++ b/src/shared/Command.ts @@ -0,0 +1,44 @@ +export enum Command { + Open = "open", + TabOpen = "tabopen", + WindowOpen = "winopen", + Buffer = "buffer", + BufferDelete = "bdelete", + BufferDeleteForce = "bdelete!", + BuffersDelete = "bdeletes", + BuffersDeleteForce = "bdeletes!", + AddBookmark = "addbookmark", + Quit = "quit", + QuitAll = "quitall", + Set = "set", + Help = "help", +} + +export namespace Command { + export function members(): Command[] { + return [ + Command.Open , + Command.TabOpen , + Command.WindowOpen , + Command.Buffer , + Command.BufferDelete , + Command.BufferDeleteForce , + Command.BuffersDelete , + Command.BuffersDeleteForce , + Command.AddBookmark , + Command.Quit , + Command.QuitAll , + Command.Set , + Command.Help , + ] + } + + export function valueOf(value: string): Command { + const map = new Map(members().map(cmd => [cmd.toString(), cmd])); + const cmd = map.get(value); + if (!cmd) { + throw new Error(`unknown command '${value}`); + } + return cmd; + } +} diff --git a/src/shared/CompletionType.ts b/src/shared/CompletionType.ts new file mode 100644 index 0000000..e104455 --- /dev/null +++ b/src/shared/CompletionType.ts @@ -0,0 +1,7 @@ +enum CompletionType { + SearchEngines, + History, + Bookmarks, +} + +export default CompletionType;
\ No newline at end of file diff --git a/src/shared/TabFlag.ts b/src/shared/TabFlag.ts new file mode 100644 index 0000000..b10d5c6 --- /dev/null +++ b/src/shared/TabFlag.ts @@ -0,0 +1,7 @@ +enum TabFlag { + CurrentTab = '%', + LastTab = '#', + None = '', +} + +export default TabFlag
\ No newline at end of file diff --git a/src/shared/messages.ts b/src/shared/messages.ts index 7f8bd5b..edb7935 100644 --- a/src/shared/messages.ts +++ b/src/shared/messages.ts @@ -1,16 +1,23 @@ import * as operations from './operations'; +import CompletionType from "./CompletionType"; +import TabFlag from "./TabFlag"; export const BACKGROUND_OPERATION = 'background.operation'; export const CONSOLE_UNFOCUS = 'console.unfocus'; export const CONSOLE_ENTER_COMMAND = 'console.enter.command'; export const CONSOLE_ENTER_FIND = 'console.enter.find'; -export const CONSOLE_QUERY_COMPLETIONS = 'console.query.completions'; export const CONSOLE_SHOW_COMMAND = 'console.show.command'; export const CONSOLE_SHOW_ERROR = 'console.show.error'; export const CONSOLE_SHOW_INFO = 'console.show.info'; export const CONSOLE_SHOW_FIND = 'console.show.find'; export const CONSOLE_HIDE = 'console.hide'; +export const CONSOLE_GET_COMPLETION_TYPES = 'console.get.completion.types'; +export const CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE = 'console.qresut.searchEngines'; +export const CONSOLE_REQUEST_BOOKMARKS = 'console.request.bookmarks'; +export const CONSOLE_REQUEST_HISTORY = 'console.request.history'; +export const CONSOLE_REQUEST_TABS = 'console.request.tabs'; +export const CONSOLE_GET_PROPERTIES = 'console.get.properties'; export const FOLLOW_START = 'follow.start'; export const FOLLOW_REQUEST_COUNT_TARGETS = 'follow.request.count.targets'; @@ -67,11 +74,6 @@ export interface ConsoleEnterFindMessage { text?: string; } -export interface ConsoleQueryCompletionsMessage { - type: typeof CONSOLE_QUERY_COMPLETIONS; - text: string; -} - export interface ConsoleShowCommandMessage { type: typeof CONSOLE_SHOW_COMMAND; command: string; @@ -95,6 +97,64 @@ export interface ConsoleHideMessage { type: typeof CONSOLE_HIDE; } +export interface ConsoleGetCompletionTypesMessage { + type: typeof CONSOLE_GET_COMPLETION_TYPES; +} + +export interface ConsoleRequestSearchEnginesMessage { + type: typeof CONSOLE_REQUEST_SEARCH_ENGINES_MESSAGE; + query: string +} + +export interface ConsoleRequestBookmarksMessage { + type: typeof CONSOLE_REQUEST_BOOKMARKS; + query: string; +} + +export interface ConsoleRequestHistoryMessage { + type: typeof CONSOLE_REQUEST_HISTORY; + query: string; +} + +export interface ConsoleRequestTabsMessage { + type: typeof CONSOLE_REQUEST_TABS; + query: string; + excludePinned: boolean; +} + +export interface ConsoleGetPropertiesMessage { + type: typeof CONSOLE_GET_PROPERTIES; +} + +export type ConsoleRequesttabsResponse = { + index: number + flag: TabFlag + title: string + url: string + faviconUrl?: string +}[] + +export type ConsoleGetCompletionTypesResponse = CompletionType[]; + +export type ConsoleRequestSearchEnginesResponse = { + title: string; +}[] + +export type ConsoleRequestBookmarksResponse = { + title: string; + url: string; +}[] + +export type ConsoleRequestHistoryResponse = { + title: string; + url: string; +}[] + +export type ConsoleGetPropertiesResponse = { + name: string + type: 'string' | 'boolean' | 'number' +}[] + export interface FollowStartMessage { type: typeof FOLLOW_START; newTab: boolean; @@ -231,12 +291,17 @@ export type Message = ConsoleUnfocusMessage | ConsoleEnterCommandMessage | ConsoleEnterFindMessage | - ConsoleQueryCompletionsMessage | ConsoleShowCommandMessage | ConsoleShowErrorMessage | ConsoleShowInfoMessage | ConsoleShowFindMessage | ConsoleHideMessage | + ConsoleRequestBookmarksMessage | + ConsoleRequestHistoryMessage | + ConsoleRequestTabsMessage | + ConsoleGetPropertiesMessage | + ConsoleGetCompletionTypesMessage | + ConsoleRequestSearchEnginesMessage | FollowStartMessage | FollowRequestCountTargetsMessage | FollowResponseCountTargetsMessage | @@ -270,7 +335,6 @@ export const valueOf = (o: any): Message => { case CONSOLE_UNFOCUS: case CONSOLE_ENTER_COMMAND: case CONSOLE_ENTER_FIND: - case CONSOLE_QUERY_COMPLETIONS: case CONSOLE_SHOW_COMMAND: case CONSOLE_SHOW_ERROR: case CONSOLE_SHOW_INFO: |