Exemplo n.º 1
0
func main() {
	tab := fmttab.New("Environments", fmttab.BorderDouble, nil)
	tab.AddColumn("ENV", 25, fmttab.AlignLeft).
		AddColumn("VALUE", 25, fmttab.AlignLeft)
	for _, env := range os.Environ() {
		keyval := strings.Split(env, "=")
		tab.AppendData(map[string]interface{}{
			"ENV":   keyval[0],
			"VALUE": keyval[1],
		})
	}
	tab.Columns[0].Caption = "Environment"
	tab.WriteTo(os.Stdout)
}
Exemplo n.º 2
0
func main() {
	tab := fmttab.New("Table without border:", fmttab.BorderNone, nil)
	tab.AddColumn("Key", 15, fmttab.AlignLeft).
		AddColumn("Value", 15, fmttab.AlignRight)
	tab.Data = []map[string]interface{}{
		{
			"Key":   "Key One",
			"Value": "Value One",
		},
		{
			"Key":   "Key Two",
			"Value": "Value Two",
		},
	}
	tab.WriteTo(os.Stdout)
}
Exemplo n.º 3
0
func main() {
	tab := fmttab.New("Environments:", fmttab.BorderNone, nil)
	tab.Columns = []*fmttab.Column{
		{
			Name: "ENV", Width: 25, Aling: fmttab.AlignLeft,
		},
		{
			Name: "VALUE", Width: 25, Aling: fmttab.AlignLeft,
		},
	}
	for _, env := range os.Environ() {
		keyval := strings.Split(env, "=")
		tab.Data = append(tab.Data, map[string]interface{}{
			"ENV":   keyval[0],
			"VALUE": keyval[1],
		})
	}
	tab.WriteTo(os.Stdout)
}
Exemplo n.º 4
0
func main() {
	tab := fmttab.New("Environments", fmttab.BorderDouble, nil)
	tab.AddColumn("ENV", fmttab.WidthAuto, fmttab.AlignLeft).
		AddColumn("VALUE", 20, fmttab.AlignLeft)
	for _, env := range os.Environ() {
		keyval := strings.Split(env, "=")
		tab.AppendData(map[string]interface{}{
			"ENV":   keyval[0],
			"VALUE": keyval[1],
		})
	}
	tab.WriteTo(os.Stdout)

	//Autofit
	err := termbox.Init()
	if err != nil {
		panic(err)
	}
	termwidth, _ := termbox.Size()
	termbox.Close()
	tab.AutoSize(true, termwidth)
	tab.WriteTo(os.Stdout)

}
Exemplo n.º 5
0
func doOutputTable(dbs []db.Database, ctx *action.Context) error {
	datasets := ctx.Get("datasets").(*dataset.CollectionDataset)
	table := fmttab.New("", fmttab.BorderThin, nil)
	table.AddColumn("_CODE_", 10, fmttab.AlignLeft)
	ctx.Set("table", table)

	for _, col := range datasets.GetUniqueColumnsNames() {
		table.AddColumn(col, 15, fmttab.AlignLeft)
	}
	for _, ds := range datasets.GetDatasets() {
		for _, row := range ds.Rows {
			table.AppendData(row.GetDataMap())
		}
	}

	pget := ctx.Get("params").(parametergetter.ParameterGetter)

	if pget.GetDef(parametergetter.AutoFitWidthColumns, true).(bool) {
		//todo: move into fmttab
		cols := table.Columns.ColumnsVisible()
		for c, col := range cols {
			max := utf8.RuneCountInString(col.Name)
			for i := 0; i < len(table.Data); i++ {
				val, ok := table.Data[i][col.Name]

				if ok && val != nil {
					fval := fmt.Sprintf("%v", val)
					l := utf8.RuneCountInString(fval)
					if l > max {
						max = l
					}
				}
			}
			if max != 0 {
				cols[c].Width = max
			}
		}
	}

	switch pget.GetDef(parametergetter.BorderTable, "").(string) {
	case "Thin":
		table.SetBorder(fmttab.BorderThin)
	case "Double":
		table.SetBorder(fmttab.BorderDouble)
	case "None":
		table.SetBorder(fmttab.BorderNone)
	case "Simple":
		table.SetBorder(fmttab.BorderSimple)
	}

	tabex.SetTableSubFormat(table, ctx.GetDef("subformat", "").(string))

	if pget.GetDef(parametergetter.Fit, true).(bool) {

		if e := termbox.Init(); e != nil {
			return e
		}
		tw, _ := termbox.Size()
		table.AutoSize(true, tw)
		termbox.Close()
	}

	if _, err := table.WriteTo(os.Stdout); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 6
0
func listParams() cli.Command {
	return cli.Command{
		Name:  "list",
		Usage: "list of parametrs",
		Flags: []cli.Flag{
			cli.BoolFlag{
				Name:  "fit",
				Usage: "use for fit table by width window of terminal",
			},
			cli.StringFlag{
				Name:  "border",
				Usage: "set type of border table: Thin,Double,Simple or None. Default:Thin",
			},
		},
		Action: func(ctx *cli.Context) {
			logger.Trace.Println("command params list")
			defer logger.Trace.Println("command params list done")
			d := parameters.GetInstance()
			defer checkErr(d.Close)
			params, err := d.All()
			if err != nil {
				panic(err)
			}
			tab := fmttab.New("List of databases", fmttab.BorderThin, nil)

			tab.AddColumn("Id", 4, fmttab.AlignRight)
			tab.AddColumn("Name", fmttab.WidthAuto, fmttab.AlignLeft)
			tab.AddColumn("Value", fmttab.WidthAuto, fmttab.AlignLeft)
			tab.AddColumn("Description", fmttab.WidthAuto, fmttab.AlignLeft)
			for _, curd := range params.Get() {
				rec := make(map[string]interface{})
				rec["Id"] = curd.ID
				rec["Name"] = curd.Name
				rec["Value"] = curd.ValueStr()
				rec["Description"] = curd.Description
				tab.AppendData(rec)
			}
			pget := parametergetter.New(ctx, parameters.GetInstance())
			if pget.GetDef(parametergetter.Fit, false).(bool) {
				if e := termbox.Init(); e != nil {
					panic(e)
				}
				tw, _ := termbox.Size()
				tab.AutoSize(true, tw)
				termbox.Close()
			}
			switch pget.GetDef(parametergetter.BorderTable, "").(string) {
			case "Thin":
				tab.SetBorder(fmttab.BorderThin)
			case "Double":
				tab.SetBorder(fmttab.BorderDouble)
			case "None":
				tab.SetBorder(fmttab.BorderNone)
			case "Simple":
				tab.SetBorder(fmttab.BorderSimple)
			}

			if _, err := tab.WriteTo(os.Stdout); err != nil {
				panic(err)
			}
		},
	}
}
Exemplo n.º 7
0
Arquivo: db.go Projeto: arteev/dsql
func listDatabase() cli.Command {

	dbFilterFlags := newCliFlags(cliOption{
		Databases:        modeFlagMulti,
		ExcludeDatabases: modeFlagMulti,
		Engines:          modeFlagMulti,
		Tags:             modeFlagMulti,
		ExcludeTags:      modeFlagMulti,
	})

	return cli.Command{
		Name:  "list",
		Usage: "list of databases",
		Flags: append(dbFilterFlags.Flags(),
			cli.BoolFlag{
				Name:  "fit",
				Usage: "use for fit table by width window of terminal",
			},
			cli.StringFlag{
				Name:  "border",
				Usage: "set type of border table: Thin,Double,Simple or None. Default:Thin",
			}),
		Action: func(ctx *cli.Context) error {
			logger.Trace.Println("command list database")
			dbFilterFlags.SetContext(ctx)
			d := db.GetInstance()
			dbs, err := d.All()
			if err != nil {
				return err
			}
			for _, e := range dbFilterFlags.Engines() {
				rdb.CheckCodeEngine(e)
			}
			dbFilterFlags.ApplyTo(dbs)

			tab := fmttab.New("List of databases", fmttab.BorderThin, nil)
			tab.AddColumn("Id", 4, fmttab.AlignRight)
			tab.AddColumn("On", 2, fmttab.AlignLeft)
			tab.AddColumn("Code", 10, fmttab.AlignLeft)
			tab.AddColumn("Engine", 11, fmttab.AlignLeft)
			tab.AddColumn("URI", 40, fmttab.AlignLeft)
			tab.AddColumn("Tags", 25, fmttab.AlignLeft)
			for _, curd := range dbs.Get() {
				rec := make(map[string]interface{})
				rec["Id"] = curd.ID
				if curd.Enabled {
					rec["On"] = "+"
				}
				rec["Code"] = curd.Code
				rec["URI"] = curd.ConnectionString
				rec["Engine"] = curd.Engine
				rec["Tags"] = curd.TagsComma(";")
				tab.AppendData(rec)
			}
			pget := parametergetter.New(ctx, parameters.GetInstance())
			if pget.GetDef(parametergetter.Fit, false).(bool) {
				if e := termbox.Init(); e != nil {
					panic(e)
				}
				tw, _ := termbox.Size()
				tab.AutoSize(true, tw)
				termbox.Close()
			}
			switch pget.GetDef(parametergetter.BorderTable, "").(string) {
			case "Thin":
				tab.SetBorder(fmttab.BorderThin)
			case "Double":
				tab.SetBorder(fmttab.BorderDouble)
			case "None":
				tab.SetBorder(fmttab.BorderNone)
			case "Simple":
				tab.SetBorder(fmttab.BorderSimple)
			}
			_, err = tab.WriteTo(os.Stdout)
			return err
		},
	}
}