basic main
This commit is contained in:
		
							父節點
							
								
									c9df23dd3c
								
							
						
					
					
						當前提交
						80fad75a59
					
				
							
								
								
									
										53
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								main.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/gdamore/tcell/v2"
 | 
				
			||||||
 | 
						"github.com/rivo/tview"
 | 
				
			||||||
 | 
						"github.com/spf13/cobra"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						NormalMode  = "normal"
 | 
				
			||||||
 | 
						FocusedMode = "focused"
 | 
				
			||||||
 | 
						SearchMode  = "search"
 | 
				
			||||||
 | 
						ExMode      = "ex"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type UI struct {
 | 
				
			||||||
 | 
						Mode string
 | 
				
			||||||
 | 
						App  *tview.Application
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (ui *UI) handleInput(event *tcell.EventKey) *tcell.EventKey {
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newUI() *UI {
 | 
				
			||||||
 | 
						app := tview.NewApplication()
 | 
				
			||||||
 | 
						ui := UI{
 | 
				
			||||||
 | 
							Mode: NormalMode,
 | 
				
			||||||
 | 
							App:  app,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						app.SetInputCapture(ui.handleInput)
 | 
				
			||||||
 | 
						return &ui
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _main() error {
 | 
				
			||||||
 | 
						cmd := &cobra.Command{
 | 
				
			||||||
 | 
							Use: "porphyry",
 | 
				
			||||||
 | 
							RunE: func(cmd *cobra.Command, args []string) error {
 | 
				
			||||||
 | 
								return newUI().App.Run()
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return cmd.Execute()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func main() {
 | 
				
			||||||
 | 
						if err := _main(); err != nil {
 | 
				
			||||||
 | 
							fmt.Fprintf(os.Stderr, err.Error()+"\n")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user