pynezzentials

package module
v0.0.0-...-7e438e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2024 License: MIT Imports: 3 Imported by: 0

README

Pynezzentials

GitHub go.mod Go version Go Report Card License

Pynezzentials is a Go package that provides some utilities for my personal projects. It is not intended to be a general-purpose library, but it may be useful for some people.

Features

  • cryptoutils: A set of utilities for encrypting and decrypting data.
  • fsUtils: A set of utilities for working with files.
  • ansi: A set of utilities for working with ANSI escape codes.

Installation

To install Pynezzentials, run:

go get -u github.com/pynezz/pynezzentials

Usage

package main

import (
    "fmt"
    utils "github.com/pynezz/pynezzentials"
)

func main() {
    fmt.Println(utils.Bold("Hello, world!"))
}

IPC

UNIX Domain sockets inter process communication (IPC) is a mechanism for exchanging data between processes running on the same host operating system. Pynezzentials provides a simple way to create a server and client for IPC.

Server
package main

import (
    "fmt"
    "github.com/pynezz/pynezzentials/ipc"
)

func main() {
    server := ipc.NewIPCServer("servername", [4]byte{0, 0, 0, 1})  // Identifier for the server

    server.LoadModules("config.txt")

    server.Listen(func(data []byte) []byte {
        fmt.Println("Received data:", string(data))
        return []byte("Hello, client!")
    })
}
Client
package main

import (
    "fmt"
    "github.com/pynezz/pynezzentials/ipc"
)

func main() {
    client := ipc.NewIPCClient("client1", [4]byte{0, 0, 0, 1})   // Identifier must match the server's identifier
    err := client.Connect()
    if err != {
        fmt.Println("Error:", err)
    }

    msg := client.CreateGenericReq([]byte("Hello, server!"), ipc.MSG_MSG, icp.DATA_JSON)

    response, err = client.SendIPCMessage(msg)
    if err != nil {
        fmt.Println("Error:", err)
    } else {
        fmt.Println("Received response:", string(response))
    }
}

License

LICENSE

Documentation

Index

Constants

View Source
const (
	Reset  = "\033[0m" // Reset the escape sequence
	Red    = "\033[31m"
	Green  = "\033[32m"
	Yellow = "\033[33m"
	Blue   = "\033[34m"
	Purple = "\033[35m"
	Cyan   = "\033[36m"
	Gray   = "\033[37m"
	White  = "\033[97m"
)

Ansi colors

View Source
const (
	Bold      = "\033[1m"
	Underline = "\033[4m"
	Inverse   = "\033[7m"
)

Ansi styles

View Source
const (
	LightRed    = "\033[91m"
	LightGreen  = "\033[92m"
	LightYellow = "\033[93m"
	LightBlue   = "\033[94m"
	LightPurple = "\033[95m"
	LightCyan   = "\033[96m"
)

Ansi 256 light colors

View Source
const (
	DarkRed    = "\033[31m"
	DarkGreen  = "\033[32m"
	DarkYellow = "\033[33m"
	DarkBlue   = "\033[34m"
	DarkPurple = "\033[35m"
	DarkCyan   = "\033[36m"
)

Ansi 256 dark colors

View Source
const (
	BgRed    = "\033[41m"
	BgGreen  = "\033[42m"
	BgYellow = "\033[43m"
	BgBlue   = "\033[44m"
	BgPurple = "\033[45m"
	BgCyan   = "\033[46m"
	BgGray   = "\033[47m"
)

Background colors

View Source
const (
	CursorUp    = "\033[A" // Move the cursor up
	CursorDown  = "\033[B" // Move the cursor down
	CursorRight = "\033[C" // Move the cursor right
	CursorLeft  = "\033[D" // Move the cursor left
)

Cursor movement

View Source
const (
	ClearScreen = "\033[2J" // Clear the screen
	ClearLine   = "\033[K"  // Clear the current line
	Backspace   = "\b"      // Backspace key
	Delete      = "\033[3~" // Delete key
	Enter       = "\r"      // Return carriage
	Tab         = "\t"      // Tab

	// Cursor positioning
	Home     = "\033[H"
	Position = "\033[%d;%dH"
	GetPos   = "\033[6n"

	// Save and restore cursor position
	SaveCursor    = "\033[s"
	RestoreCursor = "\033[u"

	// Hide and show cursor
	HideCursor = "\033[?25l"
	ShowCursor = "\033[?25h"

	// Overwrite the current line
	Overwrite = "\033[1A\033[2K"
)

Terminal control

View Source
const (
	RoundedTopLeft     = "╭" // Top left corner of a rounded box
	RoundedTopRight    = "╮" // Top right corner of a rounded box
	RoundedBottomLeft  = "╰" // Bottom left corner of a rounded box
	RoundedBottomRight = "╯" // Bottom right corner of a rounded box
	RoundedHoriz       = "─" // Horizontal line of a rounded box
	RoundedVert        = "│" // Vertical line of a rounded box
)

Rounded box characters

Variables

This section is empty.

Functions

func AddPadding

func AddPadding(content string, width int) string

AddPadding adds padding to a string to make it a certain width

func ColorF

func ColorF(color, format string, a ...interface{}) string

ColorF returns a formatted string with a color

func Errorf

func Errorf(format string, a ...interface{}) error

ErrorF returns a formatted error message

func FormatRoundedBox

func FormatRoundedBox(content string) string

FormatRoundedBox formats a string into a rounded box with proper padding

func GetCursorPos

func GetCursorPos() string

func GetWidth

func GetWidth(content string) int

Get the width of a multiline string

func ItalicF

func ItalicF(format string, a ...interface{}) string

ItalicF returns a formatted string with italic style

func PrintBold

func PrintBold(msg string)

PrintBold prints a bold message to the console

func PrintColor

func PrintColor(color, msg string)

PrintColor prints a colored message to the console

func PrintColorAndBg

func PrintColorAndBg(color, bg, msg string)

PrintColorAndBg prints a colored message with a background to the console

func PrintColorAndBgBold

func PrintColorAndBgBold(color, bg, msg string)

PrintColorAndBgBold prints a colored bold message with a background to the console

func PrintColorBold

func PrintColorBold(color, msg string)

PrintColorBold prints a colored bold message to the console

func PrintColorUnderline

func PrintColorUnderline(color, msg string)

PrintColorUnderline prints a colored underlined message to the console

func PrintColorf

func PrintColorf(color, format string, a ...interface{})

PrintColorf prints a colored formatted message to the console

func PrintDebug

func PrintDebug(msg string)

PrintDebug prints a debug message to the console

func PrintError

func PrintError(msg string)

PrintError prints an error message to the console

func PrintErrorf

func PrintErrorf(format string, a ...interface{})

PrintErrorf prints a formatted error message to the console

func PrintInfo

func PrintInfo(msg string)

PrintInfo prints an info message to the console

func PrintInverse

func PrintInverse(msg string)

PrintInverse prints an inverted message to the console

func PrintItalic

func PrintItalic(msg string)

PrintItalic prints an italic message to the console

func PrintRoundedBottom

func PrintRoundedBottom(width int)

PrintRoundedBottom prints a rounded bottom

func PrintRoundedTop

func PrintRoundedTop(width int)

PrintRoundedTop prints a rounded top

func PrintSuccess

func PrintSuccess(msg string)

PrintSuccess prints a success message to the console

func PrintUnderline

func PrintUnderline(msg string)

PrintUnderline prints an underlined message to the console

func PrintWarning

func PrintWarning(msg string)

PrintWarning prints a warning message to the console

func SPrintRoundedBottom

func SPrintRoundedBottom(width int) string

SPrintRoundedBottom returns a string with a rounded bottom

func SPrintRoundedTop

func SPrintRoundedTop(width int) string

SPrintRoundedTop returns a string with a rounded top

func SetCursorPos

func SetCursorPos(x, y int)

SetCursorPos sets the cursor position

func TimeToUnixTimestamp

func TimeToUnixTimestamp(t time.Time) int64

TimeToUnixTimestamp converts a time.Time object to a Unix timestamp.

func TimestampToTime

func TimestampToTime(timestamp string) time.Time

func UnixMilliTimestamp

func UnixMilliTimestamp() int64

UnixMilliTimestamp returns the current Unix timestamp in milliseconds.

func UnixNanoTimestamp

func UnixNanoTimestamp() int64

UnixNanoTimestamp returns the current Unix timestamp in nanoseconds.

func UnixNanoToTime

func UnixNanoToTime(unixNanoTimestamp int64) time.Time

UnixNanoToTime converts a Unix timestamp in nanoseconds to a time.Time object.

func UnixTimeToTime

func UnixTimeToTime(unixTimestamp int64) time.Time

UnixTimeToTime converts a Unix timestamp to a time.Time object.

func UnixTimestamp

func UnixTimestamp() int64

UnixTimestamp returns the current Unix timestamp in seconds.

func UserSessionIdValue

func UserSessionIdValue(userId uint64, timestamp time.Time) string

UserSessionIdValue generates a session ID for a user based on the user's ID and the current time.

Types

This section is empty.

Directories

Path Synopsis
ipc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL