github.com/andrewrech/lazygit@v0.8.1/pkg/gui/status_panel.go (about)

     1  package gui
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/fatih/color"
     8  	"github.com/jesseduffield/gocui"
     9  	"github.com/jesseduffield/lazygit/pkg/utils"
    10  )
    11  
    12  func (gui *Gui) refreshStatus(g *gocui.Gui) error {
    13  	v, err := g.View("status")
    14  	if err != nil {
    15  		panic(err)
    16  	}
    17  	// for some reason if this isn't wrapped in an update the clear seems to
    18  	// be applied after the other things or something like that; the panel's
    19  	// contents end up cleared
    20  	g.Update(func(*gocui.Gui) error {
    21  		v.Clear()
    22  		pushables, pullables := gui.GitCommand.GetCurrentBranchUpstreamDifferenceCount()
    23  		fmt.Fprint(v, "↑"+pushables+"↓"+pullables)
    24  		branches := gui.State.Branches
    25  		if err := gui.updateWorkTreeState(); err != nil {
    26  			return err
    27  		}
    28  		if gui.State.WorkingTreeState != "normal" {
    29  			fmt.Fprint(v, utils.ColoredString(fmt.Sprintf(" (%s)", gui.State.WorkingTreeState), color.FgYellow))
    30  		}
    31  
    32  		if len(branches) == 0 {
    33  			return nil
    34  		}
    35  		branch := branches[0]
    36  		name := utils.ColoredString(branch.Name, branch.GetColor())
    37  		repo := utils.GetCurrentRepoName()
    38  		fmt.Fprint(v, " "+repo+" → "+name)
    39  		return nil
    40  	})
    41  
    42  	return nil
    43  }
    44  
    45  func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error {
    46  	gui.Updater.CheckForNewUpdate(gui.onUserUpdateCheckFinish, true)
    47  	return gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("CheckingForUpdates"))
    48  }
    49  
    50  func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error {
    51  	if gui.popupPanelFocused() {
    52  		return nil
    53  	}
    54  
    55  	if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
    56  		return err
    57  	}
    58  	magenta := color.New(color.FgMagenta)
    59  
    60  	dashboardString := strings.Join(
    61  		[]string{
    62  			lazygitTitle(),
    63  			"Copyright (c) 2018 Jesse Duffield",
    64  			"Keybindings: https://github.com/jesseduffield/lazygit/blob/master/docs/keybindings",
    65  			"Config Options: https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md",
    66  			"Tutorial: https://youtu.be/VDXvbHZYeKY",
    67  			"Raise an Issue: https://github.com/jesseduffield/lazygit/issues",
    68  			magenta.Sprint("Buy Jesse a coffee: https://donorbox.org/lazygit"), // caffeine ain't free
    69  		}, "\n\n")
    70  
    71  	return gui.renderString(g, "main", dashboardString)
    72  }
    73  
    74  func (gui *Gui) handleOpenConfig(g *gocui.Gui, v *gocui.View) error {
    75  	return gui.openFile(gui.Config.GetUserConfig().ConfigFileUsed())
    76  }
    77  
    78  func (gui *Gui) handleEditConfig(g *gocui.Gui, v *gocui.View) error {
    79  	filename := gui.Config.GetUserConfig().ConfigFileUsed()
    80  	return gui.editFile(filename)
    81  }
    82  
    83  func lazygitTitle() string {
    84  	return `
    85     _                       _ _
    86    | |                     (_) |
    87    | | __ _ _____   _  __ _ _| |_
    88    | |/ _` + "`" + ` |_  / | | |/ _` + "`" + ` | | __|
    89    | | (_| |/ /| |_| | (_| | | |_
    90    |_|\__,_/___|\__, |\__, |_|\__|
    91                  __/ | __/ |
    92                 |___/ |___/       `
    93  }
    94  
    95  func (gui *Gui) updateWorkTreeState() error {
    96  	merging, err := gui.GitCommand.IsInMergeState()
    97  	if err != nil {
    98  		return err
    99  	}
   100  	if merging {
   101  		gui.State.WorkingTreeState = "merging"
   102  		return nil
   103  	}
   104  	rebaseMode, err := gui.GitCommand.RebaseMode()
   105  	if err != nil {
   106  		return err
   107  	}
   108  	if rebaseMode != "" {
   109  		gui.State.WorkingTreeState = "rebasing"
   110  		return nil
   111  	}
   112  	gui.State.WorkingTreeState = "normal"
   113  	return nil
   114  }