Skip to content

Commit

Permalink
feat: show code
Browse files Browse the repository at this point in the history
  • Loading branch information
miaoyin committed Nov 14, 2023
1 parent 181ee7f commit 30cc6ce
Show file tree
Hide file tree
Showing 19 changed files with 354 additions and 37 deletions.
8 changes: 8 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
10 changes: 10 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
32 changes: 32 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.17.2
plugins:
sources:
- id: trunk
ref: v1.2.6
uri: https://github.com/trunk-io/plugins
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
lint:
enabled:
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
actions:
disabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
enabled:
- trunk-upgrade-available
31 changes: 18 additions & 13 deletions app/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"slices"
"time"

"github.com/ncruces/zenity"
"github.com/pkg/browser"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/xuender/grephub/app/ag"
"github.com/xuender/grephub/app/grep"
Expand Down Expand Up @@ -65,16 +63,14 @@ func (p *Service) Config() *pb.Config {
}

func (p *Service) AddDirs() {
dirs, err := zenity.SelectFileMultiple(
zenity.Filename("."),
zenity.Directory())
if err != nil || len(dirs) == 0 {
dir, err := runtime.OpenDirectoryDialog(p.ctx, runtime.OpenDialogOptions{Title: "Select search directory"})
if err != nil || dir == "" {
slog.Error("addDirs", "err", err)

return
}

p.cfg.Dirs = append(p.cfg.GetDirs(), dirs...)
p.cfg.Dirs = append(p.cfg.GetDirs(), dir)
p.cfg.Save()
}

Expand All @@ -89,13 +85,11 @@ func (p *Service) DelDir(dir string) {
}

func (p *Service) Open(path string) {
if oss.IsWindows() {
los.Must0(browser.OpenFile(filepath.Dir(path)))

return
}
runtime.BrowserOpenURL(p.ctx, path)
}

los.Must0(browser.OpenFile(path))
func (p *Service) Dir(path string) {
runtime.BrowserOpenURL(p.ctx, filepath.Dir(path))
}

func (p *Service) recover() {
Expand All @@ -104,6 +98,17 @@ func (p *Service) recover() {
}
}

func (p *Service) File(file string) string {
data, err := os.ReadFile(file)
if err != nil {
slog.Error("file", "err", err)

return err.Error()
}

return string(data)
}

func (p *Service) Query(query *pb.Query) *pb.Result {
defer p.recover()

Expand Down
5 changes: 5 additions & 0 deletions frontend/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*",
"input": "node_modules/monaco-editor",
"output": "assets/monaco-editor/"
}
],
"styles": ["src/theme/variables.scss", "src/global.scss"],
Expand Down
34 changes: 34 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
"@capacitor/keyboard": "5.0.6",
"@capacitor/status-bar": "5.0.6",
"@ionic/angular": "^7.5.0",
"@materia-ui/ngx-monaco-editor": "^6.0.0",
"escape-html": "^1.0.3",
"ionicons": "^7.2.1",
"monaco-editor": "^0.44.0",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7907c65e26a1c716cecc3f49aa7a1e83
27a18142e58fa71b85155a7e6fdbcdc2
2 changes: 1 addition & 1 deletion frontend/src/app/ack/ack.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ion-label>{{ item?.file }}</ion-label>
</ion-item-divider>

<ion-item *ngFor="let m of item?.mates" button="true" (click)="open(item?.file)">
<ion-item *ngFor="let m of item?.mates" button="true" [routerLink]="['/code', item?.file]">
<ion-badge slot="start">{{ m.row }}</ion-badge>
<ion-label [innerHTML]="html(m)"></ion-label>
</ion-item>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/ack/ack.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CommonModule } from '@angular/common';
import { Component, Input } from '@angular/core';
import { RouterLink } from '@angular/router';
import {
IonBadge,
IonItem,
Expand All @@ -25,6 +26,7 @@ import { ApiService } from '../api/api.service';
IonLabel,
IonItemDivider,
IonBadge,
RouterLink,
CommonModule,
],
})
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ export const routes: Routes = [
redirectTo: '',
pathMatch: 'full',
},
{
path: 'code/:file',
loadComponent: () => import('./code/code.page').then((m) => m.CodePage),
},
];
25 changes: 25 additions & 0 deletions frontend/src/app/code/code.page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<ion-header [translucent]="true">
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{ file }}</ion-title>
<ion-buttons slot="end">
<ion-button (click)="open()" color="primary" title="open file">
<ion-icon name="open" slot="icon-only"></ion-icon>
</ion-button>
<ion-button (click)="dir()" color="secondary" title="open dir">
<ion-icon name="folder" slot="icon-only"></ion-icon>
</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>

<ion-content [fullscreen]="true">
<ion-header collapse="condense">
<ion-toolbar>
<ion-title size="large">{{ file }}</ion-title>
</ion-toolbar>
</ion-header>
<ngx-monaco-editor [options]="options" [(ngModel)]="code" (init)="editorInit($event)"></ngx-monaco-editor>
</ion-content>
Empty file.
17 changes: 17 additions & 0 deletions frontend/src/app/code/code.page.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { CodePage } from './code.page';

describe('CodePage', () => {
let component: CodePage;
let fixture: ComponentFixture<CodePage>;

beforeEach(async(() => {
fixture = TestBed.createComponent(CodePage);
component = fixture.componentInstance;
fixture.detectChanges();
}));

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit 30cc6ce

Please sign in to comment.