Messed up progress bars when installing npm packages inside ansi-term - emacs

I use ansi-term for all my npm and yeoman needs because it sometimes shows up dialogs that shell-mode cannot handle. It works pretty well, until I installed a package and it showed up a messed up download progress bar. Pardon the ugly output, but it looks like this:
pngquant-bin#0.1.6 postinstall /Users/avendael/tmp/yo-angular/node_modules/pngquant-bin
node lib/check.js
pngquant: downloading [ ] 3% 0.0s pngquant:
downloading [ ] 3% 0.2s pngquant: downloading [
] 6% 6.7s pngquant: downloading [ ] 6% 6.2s
pngquant: downloading [= ] 9% 8.2s pngquant:
downloading [= ] 10% 7.6s pngquant: downloading [=
] 12% 7.6s pngquant: downloading [==
] 13% 8.2s pngquant: downloading [== ] 15% 7.0s pngquant: downloading [== ] 16% 6.9s pngquant: downloading [=== ] 19% 6.8s pngquant:
downloading [=== ] 19% 7.1s pngquant: downloading
[=== ] 22% 6.5s pngquant: downloading [====
] 23% 6.2s pngquant: downloading [==== ] 25% 6.4s
pngquant: downloading [==== ] 26% 6.3s pngquant:
downloading [===== ] 28% 5.9s pngquant: downloading
[===== ] 29% 6.3s pngquant: downloading [=====
] 31% 6.0 pngquant: downloading [===== ] 32% 5.9s
pngquant: downloading [====== ] 34% 5.7s pngquant:
downloading [====== ] 36% 5.6s pngquant: downloading
[======= ] 38% 5.5s pngquant: downloading [=======
] 39% 5.3s pngquant: downloading [======= ] 41% 5.2s
pngquant: downloading [======= ] 42% 5.1s pngquant:
downloading [=======
= ] 44% 4.9s pngquant: downloading [======== ] 45% 4.7s pngquant: downloading [======== ] 47% 4.6s
pngquant: downloading [========= ] 49% 4.5s pngquant:
download ing [========= ] 50% 4.3s pngquant: downloading
[========= ] 52% 4.1s pngquant: downloading [==========
] 53% 4.0s pngquant: downloading [========== ] 55% 3.8s
pngqua nt: downloading [========== ] 57% 3.7s pngquant:
downloading [=========== ] 58% 3.5s pngquant: downloading
[=========== ] 60% 3.4s pngquant: downloading [===========
] 62% 3 .2s pngquant: downloading [============ ] 63% 3.1s
pngquant: downloading [============ ] 65% 2.9s pngquant:
downloading [============ ] 66% 2.8s pngquant: downloading
[=============
] 68% 2.6s pngquant: downloading [============= ] 69% 2.5s pngquant: downloading [============= ] 71% 2.3s pngquant:
downloading [============== ] 73% 2.2s pngquant: downloading [==
============ ] 75% 2.0s pngquant: downloading [============== ] 76% 1.9s pngquant: downloading [=============== ] 78% 1.7s
pngquant: downloading [=============== ] 79% 1.6s pngquant: dow
nloading [=============== ] 81% 1.4s pngquant: downloading
[=============== ] 82% 1.3s pngquant: downloading
[================ ] 84% 1.2s pngquant: downloading
[================ ] 85% 1.1s p ngquant: downloading
[================= ] 92% 0.6s pngquant: downloading
[===================] 98% 0.1s pngquant: downloading
[===================] 100% 0.0s
✓ pre-build test passed successfully pngquant-bin#0.1.6
node_modules/pngquant-bin
I tried it out in a terminal and it looks like a normal progress bar, with bars moving to the right as the download goes on.
I also tried installing the same package inside shell-mode, and the output (again, pardon the ugliness) looks like this:
pngquant-bin#0.1.6 postinstall /Users/avendael/tmp/yo-angular/node_modules/pngquant-bin
node lib/check.js
[1G[0J [1G pngquant: downloading [ ] 3%
0.0s[1G[0J [1G pngquant: downloading [ ] 3% 0.2s[1G[0J [1G pngquant: downloading [ ] 6% 8.7s[1G[0J [1G pngquant: downloading [ ] 6% 8.0s[1G[0J [1G pngquant: downloading [= ] 9% 6.2s[1G[0J [1G pngquant: downloading [= ] 10% 5.7s[1G[0J [1G pngquant: downloading [= ] 12% 4.9s[1G[0J [1G pngquant: downloading [== ] 13% 4.6s[1G[0J [1G pngquant: downloading [== ] 15% 6.2s[1G[0J [1G pngquant: downloading [== ] 16% 5.9s[1G[0J [1G pngquant: downloading [=== ] 19% 5.3s[1G[0J [1G pngquant: downloading [=== ] 19% 5.0s[1G[0J [1G pngquant: downloading [=== ] 22% 4.6s[1G[0J [1G pngquant: downloading [==== ] 23% 4.4s[1G[0J [1G pngquant: downloading [==== ] 25% 6.1s[1G[0J [1G pngquant: downloading [==== ] 26% 5.8s[1G[0J [1G pngquant: downloading [===== ] 32% 4.4s[1G[0J [1G pngquant: downloading [======= ] 39% 3.3s[1G[0J [1G pngquant: downloading [======= ] 41% 3.2s[1G[0J [1G pngquant: downloading [======= ] 42% 3.1s[1G[0J [1G pngquant: downloading [======== ] 44% 2.9s[1G[0J [1G pngquant: downloading [======== ] 45% 2.8s[1G[0J [1G pngquant: downloading [======== ] 47% 2.7s[1G[0J [1G pngquant: downloading [========= ] 49% 2.6s[1G[0J [1G pngquant: downloading [========= ] 50% 2.5s[1G[0J [1G pngquant: downloading [========= ] 52% 2.5s[1G[0J [1G pngquant: downloading [========== ] 53% 2.4s[1G[0J [1G pngquant: downloading [========== ] 55% 2.2s[1G[0J [1G pngquant: downloading [========== ] 57% 2.1s[1G[0J [1G pngquant: downloading [=========== ] 58% 2.0s[1G[0J [1G pngquant: downloading [=========== ] 60% 2.0s[1G[0J [1G pngquant: downloading [=========== ] 62% 1.9s[1G[0J [1G pngquant: downloading [============ ] 63% 1.8s[1G[0J [1G pngquant: downloading [============ ] 65% 1.7s[1G[0J [1G pngquant: downloading [============ ] 66% 1.6s[1G[0J [1G pngquant: downloading [============= ] 68% 1.5s[1G[0J [1G pngquant: downloading [============= ] 69% 1.5s[1G[0J [1G pngquant: downloading [============= ] 71% 1.3s[1G[0J [1G pngquant: downloading [============== ] 73% 1.3s[1G[0J [1G pngquant: downloading [============== ] 75% 1.2s[1G[0J [1G pngquant: downloading [============== ] 76% 1.1s[1G[0J [1G pngquant: downloading [=============== ] 78% 1.0s[1G[0J [1G pngquant: downloading [=============== ] 79% 1.0s[1G[0J [1G pngquant: downloading [=============== ] 81% 0.9s[1G[0J [1G pngquant: downloading [=============== ] 82% 0.8s[1G[0J [1G pngquant: downloading [================ ] 84% 0.7s[1G[0J [1G pngquant: downloading [================ ] 85% 0.7s[1G[0J [1G pngquant: downloading [================= ] 88% 0.6s[1G[0J [1G pngquant: downloading [================= ] 88% 0.5s[1G[0J [1G pngquant: downloading [================= ] 91% 0.4s[1G[0J [1G pngquant: downloading [================= ] 92% 0.4s[1G[0J [1G pngquant: downloading [================== ] 94% 0.3s[1G[0J [1G pngquant: downloading [================== ] 95% 0.2s[1G[0J [1G pngquant: downloading [================== ] 97% 0.1s[1G[0J [1G pngquant: downloading [===================] 98% 0.1s[1G[0J [1G pngquant: downloading [===================] 100% 0.0s
✓ pre-build test passed successfully
It's pretty much the same but this time, there's a ^[[1G^[[0J ^[[1G after each bar. Any idea what's causing this?
Here's how ansi-terms stty looks like:
speed 9600 baud;
lflags: echoe echoke echoctl pendin
oflags: -oxtabs
cflags: cs8 -parenb
erase kill
<undef> <undef>
shell-mode looks like this:
speed 9600 baud;
lflags: -echo echoe echoke echoctl
oflags: -onlcr -oxtabs
cflags: cs8 -parenb
erase kill
<undef> <undef>
osx terminal's stty:
speed 9600 baud;
lflags: -echo echoe echoke echoctl
oflags: -onlcr -oxtabs
cflags: cs8 -parenb
erase kill
<undef> <undef>

Disable the spinner. The easiest way to do this is:
$ npm config set spin false
If colour is a problem:
$ npm config set color false
Finally, if you have issues with your JavaScript prompt:
$ export NODE_NO_READLINE=1
$ node
>
Hope this helps.

Related

Flow issue, Netlogo

The following lines of code informs turtle's (shoplifters) decision whether 1) their perception of risk is low enough to attempt to shoplift and 2) whether they are caught shoplifting.
If the perception-of-risk is 60 or below and they have not previously been deterred from shoplifting, they attempt to shoplift.
98% of attempts are successful.
Of the unsuccessful 2% of attempts, 5% of them are prevented. The shoplift is unsuccessful and there are no repercussions.
Of the 95% which weren't prevented, 99% of these shoplifters are apprehended by security.
1% of shoplifters who were apprehended by security escape thus successfully shoplift.
Apprehension has two effects. For the caught shoplifter, apprehension deters 97% of non-professional shoplifters to not shoplift again. For up to 5 potential shoplifters who are intending to target the same store, their perception-of-risk of shoplifting at that store increases by 5.
My question is this: The line of explanation/code with the asterisks' next to them, would this work? I am trying to increase the perception-of-risk of turtles who share the same target-store as the turtle who was apprehended.
to number-shoplifts
ask shoplifters [ if [pcolor] of patch-here = lime and
perception-of-risk <= 60 and forever-deterred = 0
[ifelse (random-float 1 < 0.98) [
set successful-shoplifts successful-shoplifts + 1 ]
[ifelse (random-float 1 < 0.05) [
set successful-shoplifts successful-shoplifts + 0 ]
[ifelse (random-float 1 < 0.99 ) [
set security-apprehension security-apprehension + 1
if professional = 0 and (random-float 1 < 0.97) [set forever-deterred 1]
*** ask n-of 5 shoplifters [if target-store = patch-here [ set perception-of-risk perception-of-risk + 5 ]]
]
[set successful-shoplifts successful-shoplifts + 1 ]
]]]]
end
The easiest way to test whether something like this works is to add some visible changes. Replace the indicated line with:
ask n-of 5 shoplifters
[ write target-store write " with risk " print perception-of-risk
if target-store = patch-here
[ set perception-of-risk perception-of-risk + 5
set color red
show perception-of-risk ]
]
The idea is to have some output that tells you what is going on.

How can I move a turtle to a patch with a probability?

It is a pretty simple model so far. I want the walker to move to the patches, but not randomly how it is now but with a probability. In this case it is the list "priority" which describes the probability for each patch (used vehicle).
So my question: How can I implement the calculated priority to the move statement?
Here's the code:
breed [nodes node]
breed [walkers walker]
globals [
cost
time
wellbeing
efficiency
vec1
vec2
vec3
nodelist
; rain
]
walkers-own [
Temp_best ;aim temp
capital ; capital for each timestep to invest in transportation
adaptation
location
priority
delta-priority
] ;; holds a node
patches-own [
]
to setup
clear-all
set-default-shape nodes "circle"
;; create a random network
create-nodes 1 [ set color white ]
create-nodes 1 [ set color blue ] ;car
create-nodes 1 [ set color yellow ] ;bike
create-nodes 1 [ set color green ] ;public transportation
ask node 0 [ create-link-with node 1 ]
ask node 0 [ create-link-with node 2 ]
ask node 0 [ create-link-with node 3 ]
;; lay it out so links are not overlapping
repeat 500 [ layout ]
;; leave space around the edges
ask nodes [ setxy 0.95 * xcor 0.95 * ycor ]
;; put some "walker" turtles on the network
create-walkers 1 [
set color red
set location node 0
move-to location
]
reset-ticks
ask walkers [
set capital 5
set adaptation 0.1
set wellbeing n-values 3 [0]
set priority n-values 3 [0] ;sum of all must be 1
set delta-priority n-values 3 [0] ;sum of all must be 0
set efficiency n-values 3 [0]
]
set cost [3.5 1 0.1]
set time [0.3 0.6 0.7]
set vec1 [0.7 0.7 0.7] ;if change one, than also the other --> sum must be 1
set vec2 [0.3 0.3 0.3] ;
set vec3 [1 1 1]
ask walkers[
output-print wellbeing
]
set cost (map * cost vec1)
set time (map * time vec2)
ask walkers[
output-print cost
output-print time
]
ask walkers [
set wellbeing (map + cost time)
set wellbeing (map / vec3 wellbeing) ;devided by 1 to have a high number for wellbeing
set priority [0 0.1 0.9]
; set priority (map + priority delta-priority)
if rain? [
set priority replace-item 2 priority 0
set priority replace-item 1 priority (1 - item 0 priority + item 2 priority)
]
]
ask walkers[
output-print wellbeing
output-print priority
]
;set efficiency replace-item 1 efficiency (wellbeing 1 / )
set efficiency (map / wellbeing cost)
output-print efficiency
;end
;to calculate
;ask walker[
;set delta-priority replace-item 0 delta-priority ( adaptation * item 0 priority * ((item 0 wellbeing) - ) - ((item 1 priority * item 1 wellbeing)+(item 2 priority * item 2 wellbeing)))
; set priority replace-item 0 priority (priority 0 + delta-priority 0)
;set priority replace-item 1 priority (priority 1 + delta-priority 1)
;set priority replace-item 2 priority (priority 2 + delta-priority 2)
; set priority (map + priority delta-priority)
;ifelse wellbeing 2 > wellbeing 1
; output-print delta-priority
; ]
end
to layout
layout-spring nodes links 0.5 2 1
end
to go
ask links [ set thickness 0 ]
ask walkers [
let new-location one-of nodes ;i want to introduce the priority for each node
;one-of [link-neighbors] of location
;; change the thickness of the link I just crossed over
;ask [link-with new-location] of location [ set thickness 0.5 ]
face new-location ;; not strictly necessary, but improves the visuals a bit
move-to new-location
set location new-location
]
tick
ask nodes
[show count walkers-here]
end

model that represents a food chain, the bird to eat the bug and the bug to eat the grass w/ energy

breed [ bug bugs ]
breed [ bird birds ]
bird-own [ energy ] ;; birds energy
bug-own [ energy ] ;; bugs energy
to setup
ca
grow-grass
set-default-shape bird "bird"
set-default-shape bug "bug"
create-bird 3 [
set color 37
setxy random-xcor random-ycor
set energy random 10
]
create-bug 20 [
set color green
setxy random-xcor random-ycor
set energy random 10
]
reset-ticks
end
to go
if not any? bugs [crt 2 ]
grow-grass
ask bugs
[ move
eat-grass
reproduce
death ]
ask birds
[ move
eat-bugs
reproduce
death ]
tick
end
to grow-grass
ask patches [
if pcolor = white [
if random-float 1000 < grass-grow-rate
[ set pcolor 57 ]
] ]
end
to move
rt random
lt random
fd 1
set energy energy -0.5
end
to eat-grass
if pcolor = 57
[ set pcolor white
set energy energy + grass-energy ]
end
to eat-bugs
if color = green
[ set pcolor black
set energy energy + ]
end
to reproduce
if energy > birth-threshold
[ set energy energy / 2
hatch 1 [ fd 1 ] ]
end
to death
if energy < 0 [ die ]
end
the birds gain energy when the they eat the bugs and the bugs gain energy when they eat the grass and they use that energy to reproduce. It won't work when i click setup I'm not sure what to do. I need to show the amount of energy they get from eating and the amount they lose from reproducing and moving around
There were several issues with how you defined your breeds. Also, you did not define some variables you use later on. I made some modifications and the basics are now working. Have a look at the energy variables and put in your own values (I made some up as I went). I also changed the eat-bugs proc and now you have birds that do eat the bugs. Finally, I out-commented the shapes of birds and bugs as this is not essential and you can always import them later on. For now, your breeds differ in color only, not shape.
Hope this helped!
breed [ bugs bug ]
breed [ birds bird ]
birds-own [ energy ] ;; birds energy
bugs-own [ energy ] ;; bugs energy
globals [grass-grow-rate
grass-energy ;; you need to define this in the setup and use it in a procedure
birth-threshold]
to setup
ca
grow-grass
;set-default-shape birds "bird"
; set-default-shape bugs "bug"
create-birds 3 [
set color red
setxy random-xcor random-ycor
set energy random 10
]
create-bugs 20 [
set color green
setxy random-xcor random-ycor
set energy random 10
]
reset-ticks
set grass-grow-rate 0.5 ;; put in your values
set birth-threshold 10 ;; ditto
end
to go
if not any? bugs [create-bugs 2 [set color green
setxy random-xcor random-ycor
set energy random 10]]
grow-grass
ask bugs
[ move
eat-grass
reproduce
death ]
ask birds
[ move
eat-bugs
reproduce
death ]
tick
end
to grow-grass
ask patches [
if pcolor = white [
if random-float 1000 < grass-grow-rate
[ set pcolor 57 ]
] ]
end
to move
rt random 100
lt random 80
fd 1
set energy energy - 0.5
end
to eat-grass
if pcolor = 57 ; what if the color is not 57? i.e. if another turtle already visited this patch?
[ set pcolor white
set energy energy + grass-energy ]
end
to eat-bugs
;suggested change for this proc:
if any? bugs
[set energy energy + 1
ask one-of bugs [die]]
;if color = green
;[ set pcolor black
; set energy energy + 1 ]
end
to reproduce
if energy > birth-threshold
[ set energy energy / 2
hatch 1 [ fd 1 ] ]
end
to death
if energy < 0 [ die ]
end
Check out "Wolf Sheep Predation" in "Models Library" -> Biology. Under Tools -> "Turtle Shapes Editor" you might be able to find relevant shapes to replace wolves and sheep.

Why won't any water squares spawn in on my netlogo simulation?

globals [grass]
;; Sheep and wolves are both breeds of turtle.
breed [sheep a-sheep] ;; sheep is its own plural, so we use "a-sheep" as the singular.
breed [wolves wolf]
turtles-own [energy] ;; both wolves and sheep have energy
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
;; check GRASS? switch.
;; if it is true, then grass grows and the sheep eat it
;; if it false, then the sheep don't need to eat
if water? [
if grass? [
ask patches [
set pcolor one-of [green brown blue]
if-else pcolor =[green blue]
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ] ;; initialize grass grow clocks randomly for brown patches
]
]
if grass? [
ask patches [
set pcolor one-of [green brown]
if-else pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ] ;; initialize grass grow clocks randomly for brown patches
]
]
]
set-default-shape sheep "sheep"
create-sheep initial-number-sheep ;; create the sheep, then initialize their variables
[
set color white
set size 1.5 ;; easier to see
set label-color blue - 2
set energy random (2 * sheep-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape wolves "wolf"
create-wolves initial-number-wolves ;; create the wolves, then initialize their variables
[
set color black
set size 2 ;; easier to see
set energy random (2 * wolf-gain-from-food)
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
;;set water count patches with [pcolor = blue]
reset-ticks
end
to go
if not any? turtles [ stop ]
ask sheep [
move
if water? [
if pcolor = blue [
set energy energy = 0
death ;;sheep drowns
]
]
if grass? [
set energy energy - 1 ;; deduct energy for sheep only if grass? switch is on
eat-grass
]
death
reproduce-sheep
]
ask wolves [
move
if water? [
if pcolor = blue [
set energy energy = 0
death
]
]
set energy energy - 1 ;; wolves lose energy as they move
catch-sheep
death
reproduce-wolves
]
if grass? [ ask patches [ grow-grass ] ]
set grass count patches with [pcolor = green]
tick
display-labels
end
to move ;; turtle procedure
rt random 50
lt random 50
fd 1
end
to eat-grass ;; sheep procedure
;; sheep eat grass, turn the patch brown
if pcolor = green [
set pcolor brown
set energy energy + sheep-gain-from-food ;; sheep gain energy by eating
]
end
to reproduce-sheep ;; sheep procedure
if random-float 100 < sheep-reproduce [ ;; throw "dice" to see if you will reproduce
set energy (energy / 2) ;; divide energy between parent and offspring
hatch 1 [ rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step
]
end
to reproduce-wolves ;; wolf procedure
if random-float 100 < wolf-reproduce [ ;; throw "dice" to see if you will reproduce
set energy (energy / 2) ;; divide energy between parent and offspring
hatch 1 [ rt random-float 360 fd 1 ] ;; hatch an offspring and move it forward 1 step
]
end
to catch-sheep ;; wolf procedure
let prey one-of sheep-here ;; grab a random sheep
if prey != nobody ;; did we get one? if so,
[ ask prey [ die ] ;; kill it
set energy energy + wolf-gain-from-food ] ;; get energy from eating
end
to death ;; turtle procedure
;; when energy dips below zero, die
if energy < 0 [ die ]
end
to grow-grass ;; patch procedure
;; countdown on brown patches: if reach 0, grow some grass
if pcolor = brown [
ifelse countdown <= 0
[ set pcolor green
set countdown grass-regrowth-time ]
[ set countdown countdown - 1 ]
]
end
to display-labels
ask turtles [ set label "" ]
if show-energy? [
ask wolves [ set label round energy ]
if grass? [ ask sheep [ set label round energy ] ]
]
end
but when I run this ( you have to place a on off switch for water? in the wolf sheep predation) it runs as if I made no changes at all. Why is this? How can I fix this?
anything related to water was added to the code by me.
You have two if statements inside the first if water? (in setup), and both respond to grass? So you do turn some patches blue, but then you execute the send if and turn all either brown or green.
Whenever you get confused, make smaller procedures. E.g.,
to color-patches
if grass? [
let patch-colors [green brown]
if water? [set patch-colors [green brown blue]]
ask patches [set pcolor one-of patch-colors]
]
end
One other problem, is that you don't want if pcolor = [green blue], which (i) will always be false and (ii) is trying to set a regrowth countdown on water patches.

Initial proportion of three different patches with only two sliders

i am trying to create a predation model in netlogo with foxes and rabbits. foxes eat rabbits and waste (left from people) und rabbits eat grass in a special pleasure ground.
the initial proportion of patches fixed in the setup should be: 65% green patches (grass), 35 % brown patches (eaten grass), 10 % margenta patches (waste from people). they can be distributed randomly.
at the moment it looks like that :
globals [grass waste]
breed [rabbits rabbit]
breed [foxes fox]
turtles-own [energy]
patches-own [countdown]
to setup
clear-all
ask patches [ set pcolor green ]
if grass? [
ask patches [
set pcolor one-of [green brown]
if-else pcolor = green
[ set countdown grass-regrowth-time ]
[ set countdown random grass-regrowth-time ]
]
]
ask patches [ set pcolor magenta ]
if waste? [
ask patches [
set pcolor one-of [ green brown magenta ]
if-else pcolor = [ green brown ]
[ set countdown waste-regeneration-time ]
[ set countdown random waste-regeneration-time ]
]
]
set-default-shape rabbits "rabbit"
create-rabbits initial-number-rabbits
[
set color white
set size 2.2
set label-color gray + 1
set energy random ( 2 * rabbit-gain-from-food)
setxy random-xcor random-ycor
]
set-default-shape foxes "fox"
create-foxes initial-number-foxes
[
set color red
set label-color gray + 1
set size 2.2
set energy random ( fox-gain-from-food )
setxy random-xcor random-ycor
]
display-labels
set grass count patches with [pcolor = green]
set waste count patches with [pcolor = magenta]
reset-ticks
end