Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module termiboard
go 1.14

require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/jaypipes/ghw v0.6.1 // indirect
github.com/shirou/gopsutil v2.20.8+incompatible
golang.org/x/sys v0.0.0-20200929083018-4d22bbb62b3c // indirect
)
34 changes: 25 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ const (
BannerBlueColor = "\033[1;36m%s\033[0m"
WarningYellowColor = "\033[1;33m%s\033[0m"
ErrorRedColor = "\033[1;31m%s\033[0m"
BoldWhite = "\033[1;37m%s\033[0m"
BoldWhiteColor = "\033[1;37m%s\033[0m"
None = "\033[0m%s\033[0m"
)

var (
showCPUInfo *bool
showCPUUsage *bool
showRAM *bool
showDisk *bool
showLocalIP *bool
showPublicIP *bool
showAll *bool
show5TopRAM *bool
showCPUInfo *bool
showCPUUsage *bool
showRAM *bool
showDisk *bool
showLocalIP *bool
showPublicIP *bool
showAll *bool
show5TopRAM *bool
showPCIDevices *bool
)

func main() {
Expand All @@ -34,12 +35,14 @@ func main() {
showLocalIP = flag.Bool("local-ip", false, "Show local IP address")
showPublicIP = flag.Bool("public-ip", false, "Show public IP address")
show5TopRAM = flag.Bool("top5-ram", false, "Show top 5 process that consume the most memory")
showPCIDevices = flag.Bool("pci-devices", false, "Show all PCI Devices")
showAll = flag.Bool("all", false, "Show all stats")
flag.Parse()

if flag.NFlag() == 0 {
*showAll = true
}

var functionsWithConditions = []struct {
condition bool
function func()
Expand All @@ -59,6 +62,19 @@ func main() {
pair.function()
}
}

//For Function called using their flags only
var functionCallArgs = []struct {
condition bool
function func()
}{
{*showPCIDevices, GetPCIDevices},
}
for _, pair := range functionCallArgs {
if pair.condition {
pair.function()
}
}
}

func printBanner() {
Expand Down
12 changes: 6 additions & 6 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func GetTopProcesses() {
return memoryPercentOfIthProcess > memoryPercentOfJthProcess
})

//Windows Compatiblilty(Leave out the System Idle Process), for more info refer #30

if runtime.GOOS == "windows" {
if processes[0].Pid == 0 {
processes = processes[1:]
}
}
//Windows Compatiblilty(Leave out the System Idle Process), for more info refer #30
if runtime.GOOS == "windows" {
if processes[0].Pid == 0 {
processes = processes[1:]
}
}

sort.Slice(processes, func(i, j int) bool {
memoryPercentOfIthProcess, err := processes[i].MemoryPercent()
Expand Down
2 changes: 1 addition & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetLocalIPAddress() {
}
ResultPrinter("Local IP Address:", "")
for _, networkInterface := range networkInterfaces { //Iterate over each Network Interface Card
StandardPrinter(BoldWhite, "\t["+string(networkInterface.Name)+"] "+networkInterface.HardwareAddr.String()) // Print Name and Hardware Address
StandardPrinter(BoldWhiteColor, "\t["+string(networkInterface.Name)+"] "+networkInterface.HardwareAddr.String()) // Print Name and Hardware Address
interfaceAddresses, err := networkInterface.Addrs() //Get the Internet Addresses of a Network Interface
if err == nil {
for _, interfaceAddress := range interfaceAddresses {
Expand Down
60 changes: 60 additions & 0 deletions pci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// +build !windows

package main

import (
"fmt"
"os"
"text/tabwriter"

"github.com/jaypipes/ghw"
)

func GetPCIDevices() {

ResultPrinter("Host PCI devices:", "")

//Create a Tab writer to STDout with padding of 3, space between column and Left Align column
const padding = 3
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', 0)
//Always Flush the Tab Writer because it is line buffered
defer w.Flush()

//TODO: Implement StandardPrinter for tabwriter
//Print Header Row of the table
fmt.Fprintln(w, "Class\tManufacturer\tName\t")

////TODO: Implement StandardPrinter for tabwriter
//Print Seperator for Header and Data of the table
fmt.Fprintln(w, "-----\t------------\t----\t")

pci, err := ghw.PCI()
if err != nil {
fmt.Printf("Error getting PCI info: %v", err)
}

devices := pci.ListDevices()
if len(devices) == 0 {
fmt.Printf("error: could not retrieve PCI devices\n")
return
}

for _, device := range devices {
vendor := device.Vendor
vendorName := vendor.Name
if len(vendor.Name) > 20 {
//Product Name Shorten
vendorName = string([]byte(vendorName)[0:17]) + "..."
}
product := device.Product
productName := product.Name
if len(product.Name) > 40 {
//Product Name Shorten
productName = string([]byte(productName)[0:37]) + "..."
}
//TODO: Implement StandardPrinter for tabwriter
//Print Data Row of the table
fmt.Fprintln(w, device.Class.Name+"\t"+vendorName+"\t"+productName+"\t")
}

}
53 changes: 53 additions & 0 deletions pci_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Reference Documentation: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-pnpentity
package main

import (
"fmt"
"os"
"text/tabwriter"

"github.com/StackExchange/wmi"
)

//Parameters are selected such that they match with Linux Counterpart as well
type PnPEntity struct {
PNPClass string
Name string
Manufacturer string
}

func GetPCIDevices() {

ResultPrinter("Host PCI devices:", "")

//Create a Tab writer to STDout with padding of 3, space between column and Left Align column
const padding = 3
w := tabwriter.NewWriter(os.Stdout, 0, 0, padding, ' ', 0)
//Always Flush the Tab Writer because it is line buffered
defer w.Flush()

//Create a slice for holding info about PCIDevices with PnPEntity properties
var PCIDevices []PnPEntity
//Query to select only the PCI Devices from Win32_PnPEntity
err := wmi.Query("Select * from Win32_PnPEntity where PNPDeviceID like '%PCI%'", &PCIDevices)
if err != nil {
StandardPrinter(ErrorRedColor, "Could not retrieve PCI Devices")
panic(err)
return
}

//TODO: Implement StandardPrinter for tabwriter
//Print Header Row of the table
fmt.Fprintln(w, "Class\tManufacturer\tName\t")

//TODO: Implement StandardPrinter for tabwriter
//Print Seperator for Header and Data of the table
fmt.Fprintln(w, "-----\t------------\t----\t")

for _, PCIDevice := range PCIDevices {
//TODO: Implement StandardPrinter for tabwriter
//Print Data Row of the table
fmt.Fprintln(w, PCIDevice.PNPClass+"\t"+PCIDevice.Manufacturer+"\t"+PCIDevice.Name+"\t")
}

}