diff options
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: |