Skip to content

Commit

Permalink
feat: impl logs root
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Bassett <[email protected]>
  • Loading branch information
cadriel committed Jun 16, 2021
1 parent a38a8fa commit 180b991
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/components/widgets/filesystem/FileEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ export default class FileEditor extends Vue {
const grammars = new Map()
grammars.set('gcode', 'source.gcode')
grammars.set('klipper-config', 'source.klipper-config')
// grammars.set('log', 'text.log')
// ... and our languages
monaco.languages.register({ id: 'gcode', extensions: ['gcode', 'g', 'gc', 'gco', 'ufp', 'nc'] })
monaco.languages.register({ id: 'klipper-config', extensions: ['cfg', 'conf'] })
// monaco.languages.register({ id: 'log', extensions: ['log'] })
// Define how commenting works.
monaco.languages.setLanguageConfiguration('gcode', {
Expand Down
7 changes: 6 additions & 1 deletion src/components/widgets/filesystem/FileSystemToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
>
<v-tabs>
<v-tab
v-for="(root, index) in roots"
v-for="(root, index) in registeredRoots"
:key="index"
@change="$emit('root-change', root)">
{{ root }}
Expand Down Expand Up @@ -172,6 +172,11 @@ export default class FileSystemToolbar extends Mixins(StatesMixin) {
this.textSearch = this.search
}
// Only show roots that have been registered.
get registeredRoots () {
return this.roots.filter(r => this.$store.state.server.info.registered_directories.includes(r))
}
handleUpload (files: FileList | File[], print: boolean) {
this.$emit('upload', files, print)
}
Expand Down
5 changes: 4 additions & 1 deletion src/monaco/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ A big thank you to;
- Applied Engineering & Design for the gcode TextMate grammar definition
https://github.com/appliedengdesign/vscode-gcode-syntax

- Microsoft for the log grammar definition
https://github.com/microsoft/vscode/blob/main/extensions/log/syntaxes/log.tmLanguage.json

- NeekSandhu for the monaco textmate documentation and libs
https://github.com/NeekSandhu/monaco-textmate
https://github.com/NeekSandhu/monaco-editor-textmate

- Nishkalkashyap for the vscode -> monaco theme converter
https://github.com/Nishkalkashyap/monaco-vscode-textmate-theme-converter
https://github.com/Nishkalkashyap/monaco-vscode-textmate-theme-converter
119 changes: 119 additions & 0 deletions src/monaco/language/log.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"name": "Log file",
"scopeName": "text.log",
"patterns": [
{
"match": "\\b(Trace)\\b:",
"name": "comment log.verbose"
},
{
"match": "(?i)\\[(verbose|verb|vrb|vb|v)\\]",
"name": "comment log.verbose"
},
{
"match": "(?<=^[\\s\\d\\p]*)\\bV\\b",
"name": "comment log.verbose"
},
{
"match": "\\b(DEBUG|Debug)\\b|(?i)\\b(debug)\\:",
"name": "markup.changed log.debug"
},
{
"match": "(?i)\\[(debug|dbug|dbg|de|d)\\]",
"name": "markup.changed log.debug"
},
{
"match": "(?<=^[\\s\\d\\p]*)\\bD\\b",
"name": "markup.changed log.debug"
},
{
"match": "\\b(HINT|INFO|INFORMATION|Info|NOTICE|II)\\b|(?i)\\b(info|information)\\:",
"name": "markup.inserted log.info"
},
{
"match": "(?i)\\[(information|info|inf|in|i)\\]",
"name": "markup.inserted log.info"
},
{
"match": "(?<=^[\\s\\d\\p]*)\\bI\\b",
"name": "markup.inserted log.info"
},
{
"match": "\\b(WARNING|WARN|Warn|WW)\\b|(?i)\\b(warning)\\:",
"name": "markup.deleted log.warning"
},
{
"match": "(?i)\\[(warning|warn|wrn|wn|w)\\]",
"name": "markup.deleted log.warning"
},
{
"match": "(?<=^[\\s\\d\\p]*)\\bW\\b",
"name": "markup.deleted log.warning"
},
{
"match": "\\b(ALERT|CRITICAL|EMERGENCY|ERROR|FAILURE|FAIL|Fatal|FATAL|Error|EE)\\b|(?i)\\b(error)\\:",
"name": "string.regexp, strong log.error"
},
{
"match": "(?i)\\[(error|eror|err|er|e|fatal|fatl|ftl|fa|f)\\]",
"name": "string.regexp, strong log.error"
},
{
"match": "(?<=^[\\s\\d\\p]*)\\bE\\b",
"name": "string.regexp, strong log.error"
},
{
"match": "\\b\\d{4}-\\d{2}-\\d{2}(T|\\b)",
"name": "comment log.date"
},
{
"match": "(?<=(^|\\s))\\d{2}[^\\w\\s]\\d{2}[^\\w\\s]\\d{4}\\b",
"name": "comment log.date"
},
{
"match": "\\d{1,2}:\\d{2}(:\\d{2}([.,]\\d{1,})?)?(Z| ?[+-]\\d{1,2}:\\d{2})?\\b",
"name": "comment log.date"
},
{
"match": "\\b([0-9a-fA-F]{40}|[0-9a-fA-F]{10}|[0-9a-fA-F]{7})\\b",
"name": "constant.language"
},
{
"match": "\\b[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}\\b",
"name": "constant.language log.constant"
},
{
"match": "\\b([0-9a-fA-F]{2,}[:-])+[0-9a-fA-F]{2,}+\\b",
"name": "constant.language log.constant"
},
{
"match": "\\b([0-9]+|true|false|null)\\b",
"name": "constant.language log.constant"
},
{
"match": "\"[^\"]*\"",
"name": "string log.string"
},
{
"match": "(?<![\\w])'[^']*'",
"name": "string log.string"
},
{
"match": "\\b([a-zA-Z.]*Exception)\\b",
"name": "string.regexp, emphasis log.exceptiontype"
},
{
"begin": "^[\\t ]*at",
"end": "$",
"name": "string.key, emphasis log.exception"
},
{
"match": "\\b[a-z]+://\\S+\\b/?",
"name": "constant.language log.constant"
},
{
"match": "(?<![\\w/\\\\])([\\w-]+\\.)+([\\w-])+(?![\\w/\\\\])",
"name": "constant.language log.constant"
}
]
}
1 change: 1 addition & 0 deletions src/store/files/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const actions: ActionTree<FilesState, RootState> = {
// New notifications
async notifyRootUpdate ({ commit }, payload: FileChangeSocketResponse) {
const root = payload.item.root
console.log('got root update', payload)
commit('setResetRoot', root)
SocketActions.serverFilesGetDirectory(root, root)
},
Expand Down
23 changes: 18 additions & 5 deletions src/store/files/getters.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { GetterTree } from 'vuex'
import { AppFile, Files, FilesState } from './types'
import { AppFile, FileRoot, Files, FilesState } from './types'
import { RootState } from '../types'

export const getters: GetterTree<FilesState, RootState> = {
/**
* Returns a directory of files and sub-directories.
*/
getDirectory: (state) => (r: string, path: string) => {
const root = r as 'gcodes' | 'config' | 'config_examples' | 'docs'
getDirectory: (state) => (r: FileRoot, path: string) => {
const root = r
if (state && state[root]) {
const dir = state[root].find(o => o.path === path)
if (dir) {
Expand All @@ -26,8 +26,8 @@ export const getters: GetterTree<FilesState, RootState> = {
/**
* Returns the properties of a root.
*/
getRootProperties: () => (r: string) => {
const root = r as 'gcodes' | 'config' | 'config_examples' | 'docs'
getRootProperties: () => (r: FileRoot) => {
const root = r

if (root === 'gcodes') {
return {
Expand Down Expand Up @@ -81,6 +81,19 @@ export const getters: GetterTree<FilesState, RootState> = {
}
}

if (root === 'logs') {
return {
readonly: true,
accepts: [],
canEdit: false,
canView: true,
canPrint: false,
canConfigure: false,
showConfigRef: false,
showSaveRestart: false
}
}

return {
readonly: true,
accepts: [],
Expand Down
12 changes: 6 additions & 6 deletions src/store/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import { RootState } from '../types'

export const defaultState = (): FilesState => {
return {
availableRoots: [],
gcodes: [],
config: [],
config_examples: [],
docs: [],
uploads: [],
download: null,
currentPaths: {},
disk_usage: {
total: 0,
used: 0,
free: 0
}
},
gcodes: [],
config: [],
config_examples: [],
docs: [],
logs: []
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/store/files/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Vue from 'vue'
import { MutationTree } from 'vuex'
import { mergeFileUpdate } from '../helpers'
import { Files, FilesState, FileUpdate, AppFile, AppFileWithMeta } from './types'
import { Files, FilesState, FileUpdate, AppFile, AppFileWithMeta, FileRoot } from './types'
import { defaultState } from './index'
import { Globals } from '@/globals'

Expand All @@ -22,7 +22,7 @@ export const mutations: MutationTree<FilesState> = {

setServerFilesGetDirectory (state, payload) {
const path = payload.directory.path
const root = payload.root as 'gcodes' | 'config' | 'config_examples' | 'docs'
const root = payload.root as FileRoot
const i = state[root].findIndex(o => o.path === path)
if (i >= 0) {
state[root].splice(i, 1, payload.directory)
Expand All @@ -32,7 +32,7 @@ export const mutations: MutationTree<FilesState> = {
},

setFileUpdate (state, payload: FileUpdate) {
const root = payload.root as 'gcodes' | 'config' | 'config_examples' | 'docs'
const root = payload.root as FileRoot
const paths = payload.paths

// Find relevant directory.
Expand All @@ -58,7 +58,7 @@ export const mutations: MutationTree<FilesState> = {
},

setItemDelete (state, payload: FileUpdate) {
const root = payload.root as 'gcodes' | 'config' | 'config_examples' | 'docs'
const root = payload.root as FileRoot
const paths = payload.paths

// Find relevant directory.
Expand Down
13 changes: 8 additions & 5 deletions src/store/files/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import { HistoryItem } from '@/store/history/types'

export interface FilesState {
[key: string]: Files[] | FilesUpload[] | FileDownload | string[] | CurrentPaths | DiskUsage | null;
availableRoots: string[];
gcodes: Files[];
config: Files[];
config_examples: Files[];
docs: Files[];
uploads: FilesUpload[];
download: FileDownload | null;
currentPaths: CurrentPaths;
disk_usage: DiskUsage;

gcodes: Files[];
config: Files[];
config_examples: Files[];
docs: Files[];
logs: Files[];
}

export interface DiskUsage {
Expand Down Expand Up @@ -132,3 +133,5 @@ export interface FileFilter {
text: string;
desc: string;
}

export type FileRoot = 'gcodes' | 'config' | 'config_examples' | 'docs' | 'logs'
2 changes: 1 addition & 1 deletion src/views/Configure.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
:draggable="false"
>
<file-system
:roots="['config', 'config_examples', 'docs']"
:roots="['config', 'config_examples', 'docs', 'logs']"
name="configure"
:max-height="620">
</file-system>
Expand Down

0 comments on commit 180b991

Please sign in to comment.