mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	Compare commits
	
		
			No commits in common. "f2ee600c280097f336609fbd0e9e16d47a3be899" and "efc69ab7692464c30a7b9119beb71d41140a1cd4" have entirely different histories.
		
	
	
		
			f2ee600c28
			...
			efc69ab769
		
	
		
| @ -126,12 +126,12 @@ func docPieceTag(tagName string, tags map[string][]tag) []docPiece { | |||||||
| 
 | 
 | ||||||
| func setupDocType(mod string, typ *doc.Type) *docPiece { | func setupDocType(mod string, typ *doc.Type) *docPiece { | ||||||
| 	docs := strings.TrimSpace(typ.Doc) | 	docs := strings.TrimSpace(typ.Doc) | ||||||
| 	tags, doc := getTagsAndDocs(docs) | 	inInterface := strings.HasPrefix(docs, "#interface") | ||||||
| 
 | 	if !inInterface { | ||||||
| 	if tags["type"] == nil { |  | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 	inInterface := tags["interface"] != nil | 
 | ||||||
|  | 	tags, doc := getTagsAndDocs(docs) | ||||||
| 
 | 
 | ||||||
| 	var interfaces string | 	var interfaces string | ||||||
| 	typeName := strings.ToUpper(string(typ.Name[0])) + typ.Name[1:] | 	typeName := strings.ToUpper(string(typ.Name[0])) + typ.Name[1:] | ||||||
| @ -168,7 +168,10 @@ func setupDocType(mod string, typ *doc.Type) *docPiece { | |||||||
| 	if tags["member"] != nil { | 	if tags["member"] != nil { | ||||||
| 		isMember = true | 		isMember = true | ||||||
| 	} | 	} | ||||||
| 	parentMod := mod | 	var parentMod string | ||||||
|  | 	if inInterface { | ||||||
|  | 		parentMod = mod | ||||||
|  | 	} | ||||||
| 	dps := &docPiece{ | 	dps := &docPiece{ | ||||||
| 		Doc: typeDoc, | 		Doc: typeDoc, | ||||||
| 		FuncName: typeName, | 		FuncName: typeName, | ||||||
| @ -188,19 +191,13 @@ func setupDocType(mod string, typ *doc.Type) *docPiece { | |||||||
| 
 | 
 | ||||||
| func setupDoc(mod string, fun *doc.Func) *docPiece { | func setupDoc(mod string, fun *doc.Func) *docPiece { | ||||||
| 	docs := strings.TrimSpace(fun.Doc) | 	docs := strings.TrimSpace(fun.Doc) | ||||||
| 	tags, parts := getTagsAndDocs(docs) | 	inInterface := strings.HasPrefix(docs, "#interface") | ||||||
| 
 | 	if (!strings.HasPrefix(fun.Name, prefix[mod]) && !inInterface) || (strings.ToLower(fun.Name) == "loader" && !inInterface) { | ||||||
| 	// i couldnt fit this into the condition below for some reason so here's a goto! |  | ||||||
| 	if tags["member"] != nil { |  | ||||||
| 		goto start |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	if (!strings.HasPrefix(fun.Name, prefix[mod]) && tags["interface"] == nil) || (strings.ToLower(fun.Name) == "loader" && tags["interface"] == nil) { |  | ||||||
| 		return nil | 		return nil | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| start: | 	tags, parts := getTagsAndDocs(docs) | ||||||
| 	inInterface := tags["interface"] != nil | 
 | ||||||
| 	var interfaces string | 	var interfaces string | ||||||
| 	funcsig := parts[0] | 	funcsig := parts[0] | ||||||
| 	doc := parts[1:] | 	doc := parts[1:] | ||||||
| @ -421,11 +418,7 @@ func main() { | |||||||
| 			modDescription := typeTag.ReplaceAllStringFunc(strings.Replace(modu.Description, "<", `\<`, -1), func(typ string) string { | 			modDescription := typeTag.ReplaceAllStringFunc(strings.Replace(modu.Description, "<", `\<`, -1), func(typ string) string { | ||||||
| 				typName := typ[1:] | 				typName := typ[1:] | ||||||
| 				typLookup := typeTable[strings.ToLower(typName)] | 				typLookup := typeTable[strings.ToLower(typName)] | ||||||
| 				ifaces := typLookup[0] + "." + typLookup[1] + "/" | 				linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s/#%s", typLookup[0], typLookup[0] + "." + typLookup[1], strings.ToLower(typName)) | ||||||
| 				if typLookup[1] == "" { |  | ||||||
| 					ifaces = "" |  | ||||||
| 				} |  | ||||||
| 				linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s#%s", typLookup[0], ifaces, strings.ToLower(typName)) |  | ||||||
| 				return fmt.Sprintf(`<a href="%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName) | 				return fmt.Sprintf(`<a href="%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName) | ||||||
| 			}) | 			}) | ||||||
| 			f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n", modDescription)) | 			f.WriteString(fmt.Sprintf("## Introduction\n%s\n\n", modDescription)) | ||||||
| @ -457,11 +450,7 @@ func main() { | |||||||
| 					htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string { | 					htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string { | ||||||
| 						typName := typ[1:] | 						typName := typ[1:] | ||||||
| 						typLookup := typeTable[strings.ToLower(typName)] | 						typLookup := typeTable[strings.ToLower(typName)] | ||||||
| 						ifaces := typLookup[0] + "." + typLookup[1] + "/" | 						linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s/#%s", typLookup[0], typLookup[0] + "." + typLookup[1], strings.ToLower(typName)) | ||||||
| 						if typLookup[1] == "" { |  | ||||||
| 							ifaces = "" |  | ||||||
| 						} |  | ||||||
| 						linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s#%s", typLookup[0], ifaces, strings.ToLower(typName)) |  | ||||||
| 						return fmt.Sprintf(`<a href="%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName) | 						return fmt.Sprintf(`<a href="%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName) | ||||||
| 					}) | 					}) | ||||||
| 					f.WriteString(fmt.Sprintf("### %s\n", htmlSig)) | 					f.WriteString(fmt.Sprintf("### %s\n", htmlSig)) | ||||||
| @ -498,10 +487,10 @@ func main() { | |||||||
| 							continue | 							continue | ||||||
| 						} | 						} | ||||||
| 						htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string { | 						htmlSig := typeTag.ReplaceAllStringFunc(strings.Replace(dps.FuncSig, "<", `\<`, -1), func(typ string) string { | ||||||
| 							typName := regexp.MustCompile(`\w+`).FindString(typ[1:]) | 							// todo: get type from global table to link to | ||||||
| 							typLookup := typeTable[strings.ToLower(typName)] | 							// other pages (hilbish page can link to hilbish.jobs#Job) | ||||||
| 							fmt.Printf("%+q, \n", typLookup) | 							typName := typ[1:] | ||||||
| 							linkedTyp := fmt.Sprintf("/Hilbish/docs/api/%s/%s/#%s", typLookup[0], typLookup[0] + "." + typLookup[1], strings.ToLower(typName)) | 							linkedTyp := strings.ToLower(typName) // TODO: link | ||||||
| 							return fmt.Sprintf(`<a href="#%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName) | 							return fmt.Sprintf(`<a href="#%s" style="text-decoration: none;">%s</a>`, linkedTyp, typName) | ||||||
| 						}) | 						}) | ||||||
| 						f.WriteString(fmt.Sprintf("#### %s\n", htmlSig)) | 						f.WriteString(fmt.Sprintf("#### %s\n", htmlSig)) | ||||||
|  | |||||||
							
								
								
									
										20
									
								
								complete.go
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								complete.go
									
									
									
									
									
								
							| @ -74,20 +74,13 @@ func splitForFile(str string) []string { | |||||||
| 
 | 
 | ||||||
| func fileComplete(query, ctx string, fields []string) ([]string, string) { | func fileComplete(query, ctx string, fields []string) ([]string, string) { | ||||||
| 	q := splitForFile(ctx) | 	q := splitForFile(ctx) | ||||||
| 	path := "" |  | ||||||
| 	if len(q) != 0 { |  | ||||||
| 		path = q[len(q) - 1] |  | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	return matchPath(path) | 	return matchPath(q[len(q) - 1]) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func binaryComplete(query, ctx string, fields []string) ([]string, string) { | func binaryComplete(query, ctx string, fields []string) ([]string, string) { | ||||||
| 	q := splitForFile(ctx) | 	q := splitForFile(ctx) | ||||||
| 	query = "" |  | ||||||
| 	if len(q) != 0 { |  | ||||||
| 	query = q[len(q) - 1] | 	query = q[len(q) - 1] | ||||||
| 	} |  | ||||||
| 
 | 
 | ||||||
| 	var completions []string | 	var completions []string | ||||||
| 
 | 
 | ||||||
| @ -158,12 +151,11 @@ func matchPath(query string) ([]string, string) { | |||||||
| 	files, _ := os.ReadDir(path) | 	files, _ := os.ReadDir(path) | ||||||
| 	for _, entry := range files { | 	for _, entry := range files { | ||||||
| 		// should we handle errors here? | 		// should we handle errors here? | ||||||
| 		file, err := entry.Info() | 		file, _ := entry.Info() | ||||||
| 		if err == nil && file.Mode() & os.ModeSymlink != 0 { | 		fileInfo, err := entry.Info() | ||||||
| 			path, err := filepath.EvalSymlinks(filepath.Join(path, file.Name())) | 		if err == nil && fileInfo.Mode() & os.ModeSymlink != 0 { | ||||||
| 			if err == nil { | 			path, _ := filepath.EvalSymlinks(filepath.Join(path, file.Name())) | ||||||
| 				file, err = os.Lstat(path) | 			file, _ = os.Lstat(path) | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if strings.HasPrefix(file.Name(), baseName) { | 		if strings.HasPrefix(file.Name(), baseName) { | ||||||
|  | |||||||
| @ -27,9 +27,12 @@ In this example, a command with the name of `hello` is created | |||||||
| that will print `Hello world!` to output. One question you may | that will print `Hello world!` to output. One question you may | ||||||
| have is: What is the `sinks` parameter? | have is: What is the `sinks` parameter? | ||||||
| 
 | 
 | ||||||
| The `sinks` parameter is a table with 3 keys: `in`, `out`, | A sink is a writable/readable pipe, or you can imagine a Lua | ||||||
| and `err`. The values of these is a <a href="/Hilbish/docs/api/hilbish/#sink" style="text-decoration: none;">Sink</a>. | file. It's used in this case to write to the proper output, | ||||||
|  | incase a user either pipes to another command or redirects somewhere else. | ||||||
| 
 | 
 | ||||||
|  | So, the `sinks` parameter is a table containing 3 sinks: | ||||||
|  | `in`, `out`, and `err`. | ||||||
| - `in` is the standard input. You can read from this sink | - `in` is the standard input. You can read from this sink | ||||||
| to get user input. (**This is currently unimplemented.**) | to get user input. (**This is currently unimplemented.**) | ||||||
| - `out` is standard output. This is usually where text meant for | - `out` is standard output. This is usually where text meant for | ||||||
| @ -37,6 +40,10 @@ output should go. | |||||||
| - `err` is standard error. This sink is for writing errors, as the | - `err` is standard error. This sink is for writing errors, as the | ||||||
| name would suggest. | name would suggest. | ||||||
| 
 | 
 | ||||||
|  | A sink has 2 methods: | ||||||
|  | - `write(str)` will write to the sink. | ||||||
|  | - `writeln(str)` will write to the sink with a newline at the end. | ||||||
|  | 
 | ||||||
| ## Functions | ## Functions | ||||||
| ### deregister(name) | ### deregister(name) | ||||||
| Deregisters any command registered with `name` | Deregisters any command registered with `name` | ||||||
|  | |||||||
| @ -103,15 +103,3 @@ This creates a timer that starts immediately. | |||||||
| Checks if `name` is a valid command. | Checks if `name` is a valid command. | ||||||
| Will return the path of the binary, or a basename if it's a commander. | Will return the path of the binary, or a basename if it's a commander. | ||||||
| 
 | 
 | ||||||
| ## Types |  | ||||||
| ## Sink |  | ||||||
| A sink is a structure that has input and/or output to/from |  | ||||||
| a desination. |  | ||||||
| 
 |  | ||||||
| ### Methods |  | ||||||
| #### write(str) |  | ||||||
| Writes data to a sink. |  | ||||||
| 
 |  | ||||||
| #### writeln(str) |  | ||||||
| Writes data to a sink with a newline at the end. |  | ||||||
| 
 |  | ||||||
|  | |||||||
| @ -38,22 +38,8 @@ The exit code has to be a number, it will be 0 otherwise and the error can be | |||||||
| These are the "low level" functions for the `hilbish.runner` interface. | These are the "low level" functions for the `hilbish.runner` interface. | ||||||
| 
 | 
 | ||||||
| + setMode(mode) > The same as `hilbish.runnerMode` | + setMode(mode) > The same as `hilbish.runnerMode` | ||||||
| + sh(input) -> table > Runs `input` in Hilbish's sh interpreter | + sh(input) -> input, code, err > Runs `input` in Hilbish's sh interpreter | ||||||
| + lua(input) -> table > Evals `input` as Lua code | + lua(input) -> input, code, err > Evals `input` as Lua code | ||||||
| 
 |  | ||||||
| The table value that runners return can have at least 4 values: |  | ||||||
| + input (string): The full input text. |  | ||||||
| + exitCode (number): Exit code (usually from a command) |  | ||||||
| + continue (boolean): Whether to prompt the user for more input |  | ||||||
| (in the case of incomplete syntax) |  | ||||||
| + err (string): A string that represents an error from the runner. |  | ||||||
| This should only be set when, for example, there is a syntax error. |  | ||||||
| It can be set to a few special values for Hilbish to throw the right |  | ||||||
| hooks and have a better looking message. |  | ||||||
| 
 |  | ||||||
| + `<command>: not-found` will throw a `command.not-found` hook |  | ||||||
| based on what `<command>` is. |  | ||||||
| + `<command>: not-executable` will throw a `command.not-executable` hook. |  | ||||||
| 
 | 
 | ||||||
| The others here are defined in Lua and have EmmyLua documentation. | The others here are defined in Lua and have EmmyLua documentation. | ||||||
| These functions should be preferred over the previous ones. | These functions should be preferred over the previous ones. | ||||||
|  | |||||||
| @ -179,12 +179,6 @@ function hilbish.jobs:foreground() end | |||||||
| --- @param cmd string | --- @param cmd string | ||||||
| function hilbish.runner.lua(cmd) end | function hilbish.runner.lua(cmd) end | ||||||
| 
 | 
 | ||||||
| --- Writes data to a sink. |  | ||||||
| function hilbish:write(str) end |  | ||||||
| 
 |  | ||||||
| --- Writes data to a sink with a newline at the end. |  | ||||||
| function hilbish:writeln(str) end |  | ||||||
| 
 |  | ||||||
| --- Starts running the job. | --- Starts running the job. | ||||||
| function hilbish.jobs:start() end | function hilbish.jobs:start() end | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -18,15 +18,22 @@ In this example, a command with the name of `hello` is created | |||||||
| that will print `Hello world!` to output. One question you may | that will print `Hello world!` to output. One question you may | ||||||
| have is: What is the `sinks` parameter? | have is: What is the `sinks` parameter? | ||||||
| 
 | 
 | ||||||
| The `sinks` parameter is a table with 3 keys: `in`, `out`, | A sink is a writable/readable pipe, or you can imagine a Lua | ||||||
| and `err`. The values of these is a @Sink. | file. It's used in this case to write to the proper output, | ||||||
|  | incase a user either pipes to another command or redirects somewhere else. | ||||||
| 
 | 
 | ||||||
|  | So, the `sinks` parameter is a table containing 3 sinks: | ||||||
|  | `in`, `out`, and `err`. | ||||||
| - `in` is the standard input. You can read from this sink | - `in` is the standard input. You can read from this sink | ||||||
| to get user input. (**This is currently unimplemented.**) | to get user input. (**This is currently unimplemented.**) | ||||||
| - `out` is standard output. This is usually where text meant for | - `out` is standard output. This is usually where text meant for | ||||||
| output should go. | output should go. | ||||||
| - `err` is standard error. This sink is for writing errors, as the | - `err` is standard error. This sink is for writing errors, as the | ||||||
| name would suggest. | name would suggest. | ||||||
|  | 
 | ||||||
|  | A sink has 2 methods: | ||||||
|  | - `write(str)` will write to the sink. | ||||||
|  | - `writeln(str)` will write to the sink with a newline at the end. | ||||||
| */ | */ | ||||||
| package commander | package commander | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								job.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								job.go
									
									
									
									
									
								
							| @ -18,7 +18,6 @@ import ( | |||||||
| var jobs *jobHandler | var jobs *jobHandler | ||||||
| var jobMetaKey = rt.StringValue("hshjob") | var jobMetaKey = rt.StringValue("hshjob") | ||||||
| 
 | 
 | ||||||
| // #type |  | ||||||
| // #interface jobs | // #interface jobs | ||||||
| // #property cmd The user entered command string for the job. | // #property cmd The user entered command string for the job. | ||||||
| // #property running Whether the job is running or not. | // #property running Whether the job is running or not. | ||||||
|  | |||||||
| @ -2,8 +2,8 @@ local bait = require 'bait' | |||||||
| local lunacolors = require 'lunacolors' | local lunacolors = require 'lunacolors' | ||||||
| 
 | 
 | ||||||
| hilbish.motd = [[ | hilbish.motd = [[ | ||||||
| 1000 commits on the Hilbish repository brings us to {cyan}Version 2.1!{reset} | Hilbish 2.0 is a {red}major{reset} update! If your config doesn't work | ||||||
| Docs, docs, docs... At least builtins work with pipes now. | anymore, that will definitely be why! A MOTD, very message, much day. | ||||||
| ]] | ]] | ||||||
| 
 | 
 | ||||||
| bait.catch('hilbish.init', function() | bait.catch('hilbish.init', function() | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								sink.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								sink.go
									
									
									
									
									
								
							| @ -11,9 +11,8 @@ import ( | |||||||
| 
 | 
 | ||||||
| var sinkMetaKey = rt.StringValue("hshsink") | var sinkMetaKey = rt.StringValue("hshsink") | ||||||
| 
 | 
 | ||||||
| // #type | // a sink is a structure that has input and/or output | ||||||
| // A sink is a structure that has input and/or output to/from | // it is like a lua file when used in popen, but specific to hilbish | ||||||
| // a desination. |  | ||||||
| type sink struct{ | type sink struct{ | ||||||
| 	writer io.Writer | 	writer io.Writer | ||||||
| 	reader io.Reader | 	reader io.Reader | ||||||
| @ -41,9 +40,6 @@ func setupSinkType(rtm *rt.Runtime) { | |||||||
| 	l.SetRegistry(sinkMetaKey, rt.TableValue(sinkMeta)) | 	l.SetRegistry(sinkMetaKey, rt.TableValue(sinkMeta)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // #member |  | ||||||
| // write(str) |  | ||||||
| // Writes data to a sink. |  | ||||||
| func luaSinkWrite(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { | func luaSinkWrite(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { | ||||||
| 	if err := c.CheckNArgs(2); err != nil { | 	if err := c.CheckNArgs(2); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @ -63,9 +59,6 @@ func luaSinkWrite(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { | |||||||
| 	return c.Next(), nil | 	return c.Next(), nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // #member |  | ||||||
| // writeln(str) |  | ||||||
| // Writes data to a sink with a newline at the end. |  | ||||||
| func luaSinkWriteln(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { | func luaSinkWriteln(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { | ||||||
| 	if err := c.CheckNArgs(2); err != nil { | 	if err := c.CheckNArgs(2); err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								timer.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								timer.go
									
									
									
									
									
								
							| @ -15,7 +15,6 @@ const ( | |||||||
| 	timerTimeout | 	timerTimeout | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // #type |  | ||||||
| // #interface timers | // #interface timers | ||||||
| // #property type What type of timer it is | // #property type What type of timer it is | ||||||
| // #property running If the timer is running | // #property running If the timer is running | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user