[GH-ISSUE #1298] clipboard paste issue #47182

Closed
opened 2026-04-28 03:24:57 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @eramax on GitHub (Nov 28, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/1298

I noticed this many times,
when I past a long contain from windows to wsl terminal using windows terminal I face this incorrect printing for the pasted input

The source (original)

explain this code
func Parse(reader io.Reader) ([]Command, error) {
	var commands []Command
	var command, modelCommand Command

	scanner := bufio.NewScanner(reader)
	scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize)
	scanner.Split(scanModelfile)
	for scanner.Scan() {
		line := scanner.Bytes()

		fields := bytes.SplitN(line, []byte(" "), 2)
		if len(fields) == 0 || len(fields[0]) == 0 {
			continue
		}

		switch string(bytes.ToUpper(fields[0])) {
		case "FROM":
			command.Name = "model"
			command.Args = string(fields[1])
			// copy command for validation
			modelCommand = command
		case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER":
			command.Name = string(bytes.ToLower(fields[0]))
			command.Args = string(fields[1])
		case "PARAMETER":
			fields = bytes.SplitN(fields[1], []byte(" "), 2)
			if len(fields) < 2 {
				return nil, fmt.Errorf("missing value for %s", fields)
			}

			command.Name = string(fields[0])
			command.Args = string(fields[1])
		case "EMBED":
			return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead")
		default:
			if !bytes.HasPrefix(fields[0], []byte("#")) {
				// log a warning for unknown commands
				log.Printf("WARNING: Unknown command: %s", fields[0])
			}
			continue
		}

		commands = append(commands, command)
		command.Reset()
	}

	if modelCommand.Args == "" {
		return nil, errors.New("no FROM line for the model was specified")
	}

	return commands, scanner.Err()
}

The terminal content

>>> """explain this code
... func Parse(reader io.Reader) ([]Command, error) {
...         var commands []Command
...         var command, modelCommand Command
...
...         scanner := bufio.NewScanner(reader)
...         scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize)
...         scanner.Split(scanModelfile)
...         for scanner.Scan() {
...                 line := scanner.Bytes()
...
...                 fields := bytes.SplitN(line, []byte(" "), 2)
...                 if len(fields) == 0 || len(fields[0]) == 0 {
...                         continue
...                 }
...
...                 switch string(bytes.ToUpper(fields[0])) {
...                 case "FROM":
...                         command.Name = "model"
...                         command.Args = string(fields[1])
...                         // copy command for validation
...                         modelCommand = command
...                 case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER":
...                         command.Name = string(bytes.ToLower(fields[0]))
...                         command.Args = string(fields[1])
...                 case "PARAMETER":
...                         fields = bytes.SplitN(fields[1], []byte(" "), 2)
...                         if len(fields) < 2 {
...                                 return nil, fmt.Errorf("missing value for %s", fields)
...                         }
...
... mmand.A                        command.Name = string(fields[0])
...                         command.Args = string(fields[1])
...                 case "EMBED":
...                         return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead")
...                 default:
...                         if !bytes.HasPrefix(fields[0], []byte("#")) {
...                                 // log a warning for unknown commands
...                                 log.Printf("WARNING: Unknown command: %s", fields[0])
...                         }
...                         continue
...                 }
...
...                 commands = append(commands, command)
...                 command.Reset()
...         }
...
...         if modelCommand.Args == "" {
...                 return nil, errors.New("no FROM line for the model was specified")
...         }
...
...         return commands, scanner.Err()
... }

image

Originally created by @eramax on GitHub (Nov 28, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/1298 I noticed this many times, when I past a long contain from windows to wsl terminal using windows terminal I face this incorrect printing for the pasted input The source (original) ```go explain this code func Parse(reader io.Reader) ([]Command, error) { var commands []Command var command, modelCommand Command scanner := bufio.NewScanner(reader) scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize) scanner.Split(scanModelfile) for scanner.Scan() { line := scanner.Bytes() fields := bytes.SplitN(line, []byte(" "), 2) if len(fields) == 0 || len(fields[0]) == 0 { continue } switch string(bytes.ToUpper(fields[0])) { case "FROM": command.Name = "model" command.Args = string(fields[1]) // copy command for validation modelCommand = command case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER": command.Name = string(bytes.ToLower(fields[0])) command.Args = string(fields[1]) case "PARAMETER": fields = bytes.SplitN(fields[1], []byte(" "), 2) if len(fields) < 2 { return nil, fmt.Errorf("missing value for %s", fields) } command.Name = string(fields[0]) command.Args = string(fields[1]) case "EMBED": return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead") default: if !bytes.HasPrefix(fields[0], []byte("#")) { // log a warning for unknown commands log.Printf("WARNING: Unknown command: %s", fields[0]) } continue } commands = append(commands, command) command.Reset() } if modelCommand.Args == "" { return nil, errors.New("no FROM line for the model was specified") } return commands, scanner.Err() } ``` The terminal content ```bash >>> """explain this code ... func Parse(reader io.Reader) ([]Command, error) { ... var commands []Command ... var command, modelCommand Command ... ... scanner := bufio.NewScanner(reader) ... scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize) ... scanner.Split(scanModelfile) ... for scanner.Scan() { ... line := scanner.Bytes() ... ... fields := bytes.SplitN(line, []byte(" "), 2) ... if len(fields) == 0 || len(fields[0]) == 0 { ... continue ... } ... ... switch string(bytes.ToUpper(fields[0])) { ... case "FROM": ... command.Name = "model" ... command.Args = string(fields[1]) ... // copy command for validation ... modelCommand = command ... case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER": ... command.Name = string(bytes.ToLower(fields[0])) ... command.Args = string(fields[1]) ... case "PARAMETER": ... fields = bytes.SplitN(fields[1], []byte(" "), 2) ... if len(fields) < 2 { ... return nil, fmt.Errorf("missing value for %s", fields) ... } ... ... mmand.A command.Name = string(fields[0]) ... command.Args = string(fields[1]) ... case "EMBED": ... return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead") ... default: ... if !bytes.HasPrefix(fields[0], []byte("#")) { ... // log a warning for unknown commands ... log.Printf("WARNING: Unknown command: %s", fields[0]) ... } ... continue ... } ... ... commands = append(commands, command) ... command.Reset() ... } ... ... if modelCommand.Args == "" { ... return nil, errors.New("no FROM line for the model was specified") ... } ... ... return commands, scanner.Err() ... } ``` ![image](https://github.com/jmorganca/ollama/assets/542413/db598d9d-e1dc-412a-b1ed-55aae9067166)
Author
Owner

@igorschlum commented on GitHub (Nov 28, 2023):

Hello @eramax,

I've attempted to identify any differences between the image and the text, but I haven't been able to locate any discrepancies. Could you please highlight the differences if there are any? If this is a copy-paste issue, I don't believe Ollama is the culprit.

I consulted Bard to inquire about any known issues when copying text from Windows and pasting it into the WSL terminal.

Yes, there are some known copy-paste issues when copying from Windows and pasting text in WSL terminal. One common issue is that Ctrl+C and Ctrl+V do not work by default for copying and pasting text in the WSL terminal. This is because these shortcuts are reserved for other functions in the Windows terminal.

To copy text from the WSL terminal, you can use the following keyboard shortcuts:

Copy: Ctrl+Shift+C
Paste: Ctrl+Shift+V
Keyboard shortcuts for copy and paste in WSL terminalOpens in a new window
devblogs.microsoft.com
Keyboard shortcuts for copy and paste in WSL terminal
You can also use the right-click context menu to copy and paste text.

Another known issue is that when copying text from a Windows application to a WSL terminal window, the formatting of the text may be lost. This is because the Windows application uses a different text encoding than the WSL terminal.

To avoid this issue, you can try the following:

Use the cat command to copy the text to a file. This will preserve the formatting of the text.
Use a third-party tool, such as PuTTY, to connect to the WSL terminal. PuTTY uses a different text encoding than the Windows terminal, so the formatting of the text will be preserved when copying it to a WSL terminal.
Here are some additional tips for copying and pasting text between Windows and WSL:

Use the correct encoding when saving files. When saving files from Windows to WSL, make sure to use the UTF-8 encoding. This will help to prevent formatting issues when copying the text to the WSL terminal.
Use a consistent editor. If you are using a different editor for Windows and WSL, you may encounter formatting issues when copying and pasting text. This is because different editors use different formatting conventions.
Be careful when copying and pasting code. If you are copying and pasting code from Windows to WSL, be careful not to introduce any unintended characters. This could cause errors when running the code in WSL.

<!-- gh-comment-id:1829937013 --> @igorschlum commented on GitHub (Nov 28, 2023): Hello @eramax, I've attempted to identify any differences between the image and the text, but I haven't been able to locate any discrepancies. Could you please highlight the differences if there are any? If this is a copy-paste issue, I don't believe Ollama is the culprit. I consulted Bard to inquire about any known issues when copying text from Windows and pasting it into the WSL terminal. Yes, there are some known copy-paste issues when copying from Windows and pasting text in WSL terminal. One common issue is that Ctrl+C and Ctrl+V do not work by default for copying and pasting text in the WSL terminal. This is because these shortcuts are reserved for other functions in the Windows terminal. To copy text from the WSL terminal, you can use the following keyboard shortcuts: Copy: Ctrl+Shift+C Paste: Ctrl+Shift+V Keyboard shortcuts for copy and paste in WSL terminal[Opens in a new window](https://devblogs.microsoft.com/commandline/copy-and-paste-arrives-for-linuxwsl-consoles/) [devblogs.microsoft.com](https://devblogs.microsoft.com/commandline/copy-and-paste-arrives-for-linuxwsl-consoles/) Keyboard shortcuts for copy and paste in WSL terminal You can also use the right-click context menu to copy and paste text. Another known issue is that when copying text from a Windows application to a WSL terminal window, the formatting of the text may be lost. This is because the Windows application uses a different text encoding than the WSL terminal. To avoid this issue, you can try the following: Use the cat command to copy the text to a file. This will preserve the formatting of the text. Use a third-party tool, such as PuTTY, to connect to the WSL terminal. PuTTY uses a different text encoding than the Windows terminal, so the formatting of the text will be preserved when copying it to a WSL terminal. Here are some additional tips for copying and pasting text between Windows and WSL: Use the correct encoding when saving files. When saving files from Windows to WSL, make sure to use the UTF-8 encoding. This will help to prevent formatting issues when copying the text to the WSL terminal. Use a consistent editor. If you are using a different editor for Windows and WSL, you may encounter formatting issues when copying and pasting text. This is because different editors use different formatting conventions. Be careful when copying and pasting code. If you are copying and pasting code from Windows to WSL, be careful not to introduce any unintended characters. This could cause errors when running the code in WSL.
Author
Owner

@technovangelist commented on GitHub (Nov 28, 2023):

Are you seeing any errors? It looks like it pasted in correctly. What error are you seeing? Im not sure what this issue is about? Let us know where any problem is and if there isn't any we can close the issue.

<!-- gh-comment-id:1830021271 --> @technovangelist commented on GitHub (Nov 28, 2023): Are you seeing any errors? It looks like it pasted in correctly. What error are you seeing? Im not sure what this issue is about? Let us know where any problem is and if there isn't any we can close the issue.
Author
Owner

@eramax commented on GitHub (Nov 28, 2023):

Hi, Thanks for check this issue,
I can explain it

this is the content that I have copied

explain this code
func Parse(reader io.Reader) ([]Command, error) {
	var commands []Command
	var command, modelCommand Command

	scanner := bufio.NewScanner(reader)
	scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize)
	scanner.Split(scanModelfile)
	for scanner.Scan() {
		line := scanner.Bytes()

		fields := bytes.SplitN(line, []byte(" "), 2)
		if len(fields) == 0 || len(fields[0]) == 0 {
			continue
		}

		switch string(bytes.ToUpper(fields[0])) {
		case "FROM":
			command.Name = "model"
			command.Args = string(fields[1])
			// copy command for validation
			modelCommand = command
		case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER":
			command.Name = string(bytes.ToLower(fields[0]))
			command.Args = string(fields[1])
		case "PARAMETER":
			fields = bytes.SplitN(fields[1], []byte(" "), 2)
			if len(fields) < 2 {
				return nil, fmt.Errorf("missing value for %s", fields)
			}

			command.Name = string(fields[0])
			command.Args = string(fields[1])
		case "EMBED":
			return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead")
		default:
			if !bytes.HasPrefix(fields[0], []byte("#")) {
				// log a warning for unknown commands
				log.Printf("WARNING: Unknown command: %s", fields[0])
			}
			continue
		}

		commands = append(commands, command)
		command.Reset()
	}

	if modelCommand.Args == "" {
		return nil, errors.New("no FROM line for the model was specified")
	}

	return commands, scanner.Err()
}

this is how it look like in the ollama after pasting

>>> """explain this code
... func Parse(reader io.Reader) ([]Command, error) {
...         var commands []Command
...         var command, modelCommand Command
...
...         scanner := bufio.NewScanner(reader)
...         scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize)
...         scanner.Split(scanModelfile)
...         for scanner.Scan() {
...                 line := scanner.Bytes()
...
...                 fields := bytes.SplitN(line, []byte(" "), 2)
...                 if len(fields) == 0 || len(fields[0]) == 0 {
...                         continue
...                 }
...
...                 switch string(bytes.ToUpper(fields[0])) {
...                 case "FROM":
...                         command.Name = "model"
...                         command.Args = string(fields[1])
...                         // copy command for validation
...                         modelCommand = command
...                 case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER":
...                         command.Name = string(bytes.ToLower(fields[0]))
...                         command.Args = string(fields[1])
...                 case "PARAMETER":
...                         fields = bytes.SplitN(fields[1], []byte(" "), 2)
...                         if len(fields) < 2 {
...                                 return nil, fmt.Errorf("missing value for %s", fields)
...                         }
...
... mmand.A                        command.Name = string(fields[0])
...                         command.Args = string(fields[1])
...                 case "EMBED":
...                         return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead")
...                 default:
...                         if !bytes.HasPrefix(fields[0], []byte("#")) {
...                                 // log a warning for unknown commands
...                                 log.Printf("WARNING: Unknown command: %s", fields[0])
...                         }
...                         continue
...                 }
...
...                 commands = append(commands, command)
...                 command.Reset()
...         }
...
...         if modelCommand.Args == "" {
...                 return nil, errors.New("no FROM line for the model was specified")
...         }
...
...         return commands, scanner.Err()
... }

In original text you can see those two lines

			command.Name = string(fields[0])
			command.Args = string(fields[1])

In ollama text you can see those two lines

... mmand.A                        command.Name = string(fields[0])
...                         command.Args = string(fields[1])

so there is mmand.A came from nowhere to the content.
hope you got it?

Best,

<!-- gh-comment-id:1830519731 --> @eramax commented on GitHub (Nov 28, 2023): Hi, Thanks for check this issue, I can explain it this is the content that I have copied ```python explain this code func Parse(reader io.Reader) ([]Command, error) { var commands []Command var command, modelCommand Command scanner := bufio.NewScanner(reader) scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize) scanner.Split(scanModelfile) for scanner.Scan() { line := scanner.Bytes() fields := bytes.SplitN(line, []byte(" "), 2) if len(fields) == 0 || len(fields[0]) == 0 { continue } switch string(bytes.ToUpper(fields[0])) { case "FROM": command.Name = "model" command.Args = string(fields[1]) // copy command for validation modelCommand = command case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER": command.Name = string(bytes.ToLower(fields[0])) command.Args = string(fields[1]) case "PARAMETER": fields = bytes.SplitN(fields[1], []byte(" "), 2) if len(fields) < 2 { return nil, fmt.Errorf("missing value for %s", fields) } command.Name = string(fields[0]) command.Args = string(fields[1]) case "EMBED": return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead") default: if !bytes.HasPrefix(fields[0], []byte("#")) { // log a warning for unknown commands log.Printf("WARNING: Unknown command: %s", fields[0]) } continue } commands = append(commands, command) command.Reset() } if modelCommand.Args == "" { return nil, errors.New("no FROM line for the model was specified") } return commands, scanner.Err() } ``` this is how it look like in the ollama after pasting ```bash >>> """explain this code ... func Parse(reader io.Reader) ([]Command, error) { ... var commands []Command ... var command, modelCommand Command ... ... scanner := bufio.NewScanner(reader) ... scanner.Buffer(make([]byte, 0, bufio.MaxScanTokenSize), bufio.MaxScanTokenSize) ... scanner.Split(scanModelfile) ... for scanner.Scan() { ... line := scanner.Bytes() ... ... fields := bytes.SplitN(line, []byte(" "), 2) ... if len(fields) == 0 || len(fields[0]) == 0 { ... continue ... } ... ... switch string(bytes.ToUpper(fields[0])) { ... case "FROM": ... command.Name = "model" ... command.Args = string(fields[1]) ... // copy command for validation ... modelCommand = command ... case "LICENSE", "TEMPLATE", "SYSTEM", "PROMPT", "ADAPTER": ... command.Name = string(bytes.ToLower(fields[0])) ... command.Args = string(fields[1]) ... case "PARAMETER": ... fields = bytes.SplitN(fields[1], []byte(" "), 2) ... if len(fields) < 2 { ... return nil, fmt.Errorf("missing value for %s", fields) ... } ... ... mmand.A command.Name = string(fields[0]) ... command.Args = string(fields[1]) ... case "EMBED": ... return nil, fmt.Errorf("deprecated command: EMBED is no longer supported, use the /embed API endpoint instead") ... default: ... if !bytes.HasPrefix(fields[0], []byte("#")) { ... // log a warning for unknown commands ... log.Printf("WARNING: Unknown command: %s", fields[0]) ... } ... continue ... } ... ... commands = append(commands, command) ... command.Reset() ... } ... ... if modelCommand.Args == "" { ... return nil, errors.New("no FROM line for the model was specified") ... } ... ... return commands, scanner.Err() ... } ``` In original text you can see those two lines ```python command.Name = string(fields[0]) command.Args = string(fields[1]) ``` In ollama text you can see those two lines ```bash ... mmand.A command.Name = string(fields[0]) ... command.Args = string(fields[1]) ``` so there is `mmand.A` came from nowhere to the content. hope you got it? Best,
Author
Owner

@igorschlum commented on GitHub (Nov 28, 2023):

Hi @eramax,

Could you please attempt to repeat the copy-paste process? If the "mmand.A" remains present, try copying less text until the issue disappears.

Once you've identified the minimum amount of text that triggers the problem, could you copy it from another application?

Please try pasting it from another application into the WSL Terminal to determine if the issue persists.

This information will be helpful in understanding the root cause of the problem. I attempted to paste the text into the macOS Terminal and could not replicate the issue.

Best,

Igor

<!-- gh-comment-id:1830960589 --> @igorschlum commented on GitHub (Nov 28, 2023): Hi @eramax, Could you please attempt to repeat the copy-paste process? If the "mmand.A" remains present, try copying less text until the issue disappears. Once you've identified the minimum amount of text that triggers the problem, could you copy it from another application? Please try pasting it from another application into the WSL Terminal to determine if the issue persists. This information will be helpful in understanding the root cause of the problem. I attempted to paste the text into the macOS Terminal and could not replicate the issue. Best, Igor
Author
Owner

@eramax commented on GitHub (Nov 29, 2023):

image
image

This is not an Ollama issue. it is a Windows terminal or wsl issue. The problem happens regardless of the amount of the pasted content and for the same content may happen and may not, I believe it is simply related to the speed at which the data is copied to the wsl. I discovered the same problem using the Linux text editor nano.

<!-- gh-comment-id:1830971349 --> @eramax commented on GitHub (Nov 29, 2023): ![image](https://github.com/jmorganca/ollama/assets/542413/4dff69eb-45c2-42bf-a660-2b57074ec739) ![image](https://github.com/jmorganca/ollama/assets/542413/b192fdf4-3a66-48a5-b7d0-3a3554ef48d8) This is not an Ollama issue. it is a Windows terminal or wsl issue. The problem happens regardless of the amount of the pasted content and for the same content may happen and may not, I believe it is simply related to the speed at which the data is copied to the wsl. I discovered the same problem using the Linux text editor nano.
Author
Owner

@igorschlum commented on GitHub (Nov 29, 2023):

@eramax, thank you for your feedback. Please close this issue so that the team can address other issues.

<!-- gh-comment-id:1830981932 --> @igorschlum commented on GitHub (Nov 29, 2023): @eramax, thank you for your feedback. Please close this issue so that the team can address other issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#47182